diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-02-17 15:25:33 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-02-17 15:43:43 +0000 |
commit | 9cd4eeefcc641dd70d026e08e9d218101b826c52 (patch) | |
tree | 56fbd7edf0607751c80663be94d29d83e0217fd0 | |
parent | c03b53da9129ae2d5ac9629c4b874d0981a7d418 (diff) | |
download | gcc-9cd4eeefcc641dd70d026e08e9d218101b826c52.zip gcc-9cd4eeefcc641dd70d026e08e9d218101b826c52.tar.gz gcc-9cd4eeefcc641dd70d026e08e9d218101b826c52.tar.bz2 |
libstdc++: Reduce header dependencies for C++20 (PR 92546)
In C++20 <memory> depends on <bits/ranges_unitialized.h> which
depends on <bits/random.h> just for a single concept. Including
<bits/random.h> also requires including <cmath>, which is huge due to
the C++17 special functions.
This change moves the concept to the <bits/uniform_int_dist.h> internal
header that exists so that <bits/stl_algobase.h> doesn't need to include
<bits/random.h>.
PR libstdc++/92546 (partial)
* include/bits/random.h (uniform_random_bit_generator): Move definition
to <bits/uniform_int_dist.h>.
* include/bits/ranges_algo.h: Include <bits/uniform_int_dist.h> instead
of <bits/random.h>.
* include/bits/ranges_algobase.h: Do not include <cmath>.
* include/bits/uniform_int_dist.h (uniform_random_bit_generator):
Move here.
* include/std/ranges: Do not include <limits>.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.
-rw-r--r-- | libstdc++-v3/ChangeLog | 11 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/random.h | 16 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ranges_algo.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ranges_algobase.h | 1 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/uniform_int_dist.h | 16 | ||||
-rw-r--r-- | libstdc++-v3/include/std/ranges | 1 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc | 2 |
7 files changed, 30 insertions, 19 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 954eb67..f4477aa 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,6 +1,17 @@ 2020-02-17 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/92546 (partial) + * include/bits/random.h (uniform_random_bit_generator): Move definition + to <bits/uniform_int_dist.h>. + * include/bits/ranges_algo.h: Include <bits/uniform_int_dist.h> instead + of <bits/random.h>. + * include/bits/ranges_algobase.h: Do not include <cmath>. + * include/bits/uniform_int_dist.h (uniform_random_bit_generator): + Move here. + * include/std/ranges: Do not include <limits>. + * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno. + + PR libstdc++/92546 (partial) * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/int_limits.h: New header. diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index d4aebf4..19307fb 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -33,9 +33,6 @@ #include <vector> #include <bits/uniform_int_dist.h> -#if __cplusplus > 201703L -# include <concepts> -#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -51,18 +48,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ -#ifdef __cpp_lib_concepts - /// Requirements for a uniform random bit generator. - template<typename _Gen> - concept uniform_random_bit_generator - = invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> - && requires - { - { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>; - { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>; - requires bool_constant<(_Gen::min() < _Gen::max())>::value; - }; -#endif + // std::uniform_random_bit_generator is defined in <bits/uniform_int_dist.h> /** * @brief A function template for converting the output of a (integral) diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index ff1b40f..f3a349e 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -33,7 +33,7 @@ #if __cplusplus > 201703L #include <bits/ranges_algobase.h> -#include <bits/random.h> // concept uniform_random_bit_generator +#include <bits/uniform_int_dist.h> // concept uniform_random_bit_generator #if __cpp_lib_concepts namespace std _GLIBCXX_VISIBILITY(default) diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h index cc24483..eedd29f 100644 --- a/libstdc++-v3/include/bits/ranges_algobase.h +++ b/libstdc++-v3/include/bits/ranges_algobase.h @@ -32,7 +32,6 @@ #if __cplusplus > 201703L -#include <cmath> #include <compare> #include <iterator> // #include <bits/range_concepts.h> diff --git a/libstdc++-v3/include/bits/uniform_int_dist.h b/libstdc++-v3/include/bits/uniform_int_dist.h index d2a0157..e3d7934 100644 --- a/libstdc++-v3/include/bits/uniform_int_dist.h +++ b/libstdc++-v3/include/bits/uniform_int_dist.h @@ -33,11 +33,27 @@ #include <type_traits> #include <limits> +#if __cplusplus > 201703L +# include <concepts> +#endif namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#ifdef __cpp_lib_concepts + /// Requirements for a uniform random bit generator. + template<typename _Gen> + concept uniform_random_bit_generator + = invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> + && requires + { + { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>; + { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>; + requires bool_constant<(_Gen::min() < _Gen::max())>::value; + }; +#endif + namespace __detail { /* Determine whether number is a power of 2. */ diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 970e904..b9ac528 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -42,7 +42,6 @@ #include <compare> #include <initializer_list> #include <iterator> -#include <limits> #include <optional> #include <tuple> diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc index 91e5566..f808132 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc @@ -10,6 +10,6 @@ std::__detail::_Adaptor<std::mt19937, unsigned long> aurng(urng); auto x = std::generate_canonical<std::size_t, std::numeric_limits<std::size_t>::digits>(urng); -// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 172 } +// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 158 } // { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3281 } |