From 32489ab56a9ec26aa2342c50bc6d40c95d353777 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 4 Jan 2018 10:21:29 +0000 Subject: [PATCH] PR libstdc++/83607 specialize Boyer-Moore searchers for std::byte PR libstdc++/83607 * include/std/functional (__is_byte_like): New trait. (__is_std_equal_to): Remove. (__boyer_moore_base_t): Use __is_byte_like instead of __is_std_equal_to. * include/experimental/functional (__is_std_equal_to): Remove. (__boyer_moore_base_t): Use __is_byte_like instead of __is_std_equal_to. * testsuite/20_util/function_objects/83607.cc: New test. From-SVN: r256231 --- libstdc++-v3/ChangeLog | 12 ++++ libstdc++-v3/include/experimental/functional | 11 +--- libstdc++-v3/include/std/functional | 35 ++++++++--- .../20_util/function_objects/83607.cc | 61 +++++++++++++++++++ 4 files changed, 100 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/83607.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 64fa7204d84e..1fca54f212df 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2018-01-04 Jonathan Wakely + + PR libstdc++/83607 + * include/std/functional (__is_byte_like): New trait. + (__is_std_equal_to): Remove. + (__boyer_moore_base_t): Use __is_byte_like instead of + __is_std_equal_to. + * include/experimental/functional (__is_std_equal_to): Remove. + (__boyer_moore_base_t): Use __is_byte_like instead of + __is_std_equal_to. + * testsuite/20_util/function_objects/83607.cc: New test. + 2018-01-03 Ville Voutilainen Protect optional's deduction guide with the feature macro diff --git a/libstdc++-v3/include/experimental/functional b/libstdc++-v3/include/experimental/functional index 950f89cfc317..de68c802661c 100644 --- a/libstdc++-v3/include/experimental/functional +++ b/libstdc++-v3/include/experimental/functional @@ -157,20 +157,13 @@ inline namespace fundamentals_v1 std::tuple<_GLIBCXX_STD_C::array<_Tp, _Len>, _Pred> _M_bad_char; }; - template - struct __is_std_equal_to : std::false_type { }; - - template<> - struct __is_std_equal_to> : std::true_type { }; - // Use __boyer_moore_array_base when pattern consists of narrow characters - // and uses std::equal_to as the predicate. + // (or std::byte) and uses std::equal_to as the predicate. template::value_type, typename _Diff = typename iterator_traits<_RAIter>::difference_type> using __boyer_moore_base_t - = std::conditional_t::value - && __is_std_equal_to<_Pred>::value, + = std::conditional_t::value, __boyer_moore_array_base<_Diff, 256, _Pred>, __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>; diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 1175deb65975..2b46ba899dd0 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -879,7 +879,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Fn _M_fn; }; -#if __cplusplus > 201402L + template + struct __is_byte_like : false_type { }; + + template + struct __is_byte_like<_Tp, equal_to<_Tp>> + : __bool_constant::value> { }; + + template + struct __is_byte_like<_Tp, equal_to> + : __bool_constant::value> { }; + +#if __cplusplus >= 201703L + // Declare std::byte (full definition is in ). + enum class byte : unsigned char; + + template<> + struct __is_byte_like> + : true_type { }; + + template<> + struct __is_byte_like> + : true_type { }; + #define __cpp_lib_not_fn 201603 /// [func.not_fn] Function template not_fn template @@ -988,20 +1010,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION tuple<_GLIBCXX_STD_C::array<_Tp, _Len>, _Pred> _M_bad_char; }; - template - struct __is_std_equal_to : false_type { }; - - template<> - struct __is_std_equal_to> : true_type { }; - // Use __boyer_moore_array_base when pattern consists of narrow characters - // and uses std::equal_to as the predicate. + // (or std::byte) and uses std::equal_to as the predicate. template::value_type, typename _Diff = typename iterator_traits<_RAIter>::difference_type> using __boyer_moore_base_t - = conditional_t::value - && __is_std_equal_to<_Pred>::value, + = conditional_t<__is_byte_like<_Val, _Pred>::value, __boyer_moore_array_base<_Diff, 256, _Pred>, __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>; diff --git a/libstdc++-v3/testsuite/20_util/function_objects/83607.cc b/libstdc++-v3/testsuite/20_util/function_objects/83607.cc new file mode 100644 index 000000000000..a752ca759a8b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/83607.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include +#include + +// PR libstdc++/83607 + +using std::boyer_moore_searcher; +using std::boyer_moore_horspool_searcher; +using std::byte; +using std::hash; +using std::equal_to; + +void +test01() +{ + constexpr auto expected = sizeof(boyer_moore_searcher); + static_assert(sizeof(boyer_moore_searcher) != expected); + using T1 = boyer_moore_searcher, equal_to>; + static_assert(sizeof(T1) == expected); + using T2 = boyer_moore_searcher; + static_assert(sizeof(T2) == expected); + using T3 = boyer_moore_searcher; + static_assert(sizeof(T3) == expected); + using T4 = boyer_moore_searcher, equal_to>; + static_assert(sizeof(T4) == expected); +} + +void +test02() +{ + constexpr auto expected = sizeof(boyer_moore_horspool_searcher); + static_assert(sizeof(boyer_moore_horspool_searcher) != expected); + using T1 = boyer_moore_horspool_searcher, equal_to>; + static_assert(sizeof(T1) == expected); + using T2 = boyer_moore_horspool_searcher; + static_assert(sizeof(T2) == expected); + using T3 = boyer_moore_horspool_searcher; + static_assert(sizeof(T3) == expected); + using T4 + = boyer_moore_horspool_searcher, equal_to>; + static_assert(sizeof(T4) == expected); +} -- 2.43.5