Skip to content

Commit b69ddbc

Browse files
authored
[libc++] Make variables in templates inline (llvm#115785)
The variables are all `constexpr`, which implies `inline`. Since they aren't `constexpr` in C++03 they're also not `inline` there. Because of that we define them out-of-line currently. Instead we can use the C++17 extension of `inline` variables, which results in the same weak definitions of the variables but without having all the boilerplate.
1 parent 889b3c9 commit b69ddbc

14 files changed

+64
-474
lines changed

libcxx/include/__random/discard_block_engine.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class _LIBCPP_TEMPLATE_VIS discard_block_engine {
4343
typedef typename _Engine::result_type result_type;
4444

4545
// engine characteristics
46-
static _LIBCPP_CONSTEXPR const size_t block_size = __p;
47-
static _LIBCPP_CONSTEXPR const size_t used_block = __r;
46+
static inline _LIBCPP_CONSTEXPR const size_t block_size = __p;
47+
static inline _LIBCPP_CONSTEXPR const size_t used_block = __r;
4848

4949
#ifdef _LIBCPP_CXX03_LANG
5050
static const result_type _Min = _Engine::_Min;
@@ -110,12 +110,6 @@ class _LIBCPP_TEMPLATE_VIS discard_block_engine {
110110
operator>>(basic_istream<_CharT, _Traits>& __is, discard_block_engine<_Eng, _Pp, _Rp>& __x);
111111
};
112112

113-
template <class _Engine, size_t __p, size_t __r>
114-
_LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
115-
116-
template <class _Engine, size_t __p, size_t __r>
117-
_LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
118-
119113
template <class _Engine, size_t __p, size_t __r>
120114
typename discard_block_engine<_Engine, __p, __r>::result_type discard_block_engine<_Engine, __p, __r>::operator()() {
121115
if (__n_ >= static_cast<int>(__r)) {

libcxx/include/__random/linear_congruential_engine.h

+4-20
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ class _LIBCPP_TEMPLATE_VIS linear_congruential_engine {
251251
static_assert(_Min < _Max, "linear_congruential_engine invalid parameters");
252252

253253
// engine characteristics
254-
static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
255-
static _LIBCPP_CONSTEXPR const result_type increment = __c;
256-
static _LIBCPP_CONSTEXPR const result_type modulus = __m;
254+
static inline _LIBCPP_CONSTEXPR const result_type multiplier = __a;
255+
static inline _LIBCPP_CONSTEXPR const result_type increment = __c;
256+
static inline _LIBCPP_CONSTEXPR const result_type modulus = __m;
257257
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
258258
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
259-
static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
259+
static inline _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
260260

261261
// constructors and seeding functions
262262
#ifndef _LIBCPP_CXX03_LANG
@@ -318,22 +318,6 @@ class _LIBCPP_TEMPLATE_VIS linear_congruential_engine {
318318
operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
319319
};
320320

321-
template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
322-
_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
323-
linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
324-
325-
template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
326-
_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
327-
linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
328-
329-
template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
330-
_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
331-
linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
332-
333-
template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
334-
_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
335-
linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
336-
337321
template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
338322
template <class _Sseq>
339323
void linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) {

0 commit comments

Comments
 (0)