Skip to content

Commit 234a760

Browse files
authored
Merge pull request #809 from cppalliance/literals
Move literals into namespace literals
2 parents 069c26a + 0cd5371 commit 234a760

File tree

5 files changed

+43
-36
lines changed

5 files changed

+43
-36
lines changed

examples/literals.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <boost/decimal.hpp>
66
#include <cassert>
77

8+
using namespace boost::decimal::literals;
9+
810
template <typename T>
911
bool float_equal(T lhs, T rhs)
1012
{

include/boost/decimal/literals.hpp

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@
2020

2121
namespace boost {
2222
namespace decimal {
23+
namespace literals {
2324

24-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char* str) -> decimal32
25+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char *str) -> decimal32
2526
{
2627
decimal32 d;
2728
from_chars(str, str + detail::strlen(str), d);
2829
return d;
2930
}
3031

31-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char* str) -> decimal32
32+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char *str) -> decimal32
3233
{
3334
decimal32 d;
3435
from_chars(str, str + detail::strlen(str), d);
3536
return d;
3637
}
3738

38-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char* str, std::size_t len) -> decimal32
39+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char *str, std::size_t len) -> decimal32
3940
{
4041
decimal32 d;
4142
from_chars(str, str + len, d);
4243
return d;
4344
}
4445

45-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char* str, std::size_t len) -> decimal32
46+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char *str, std::size_t len) -> decimal32
4647
{
4748
decimal32 d;
4849
from_chars(str, str + len, d);
@@ -51,36 +52,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char* str, std::size_t
5152

5253
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(unsigned long long v) -> decimal32
5354
{
54-
return decimal32{v};
55+
return decimal32 {v};
5556
}
5657

5758
BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(unsigned long long v) -> decimal32
5859
{
59-
return decimal32{v};
60+
return decimal32 {v};
6061
}
6162

62-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char* str) -> decimal32_fast
63+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char *str) -> decimal32_fast
6364
{
6465
decimal32_fast d;
6566
from_chars(str, str + detail::strlen(str), d);
6667
return d;
6768
}
6869

69-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char* str) -> decimal32_fast
70+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char *str) -> decimal32_fast
7071
{
7172
decimal32_fast d;
7273
from_chars(str, str + detail::strlen(str), d);
7374
return d;
7475
}
7576

76-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char* str, std::size_t len) -> decimal32_fast
77+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char *str, std::size_t len) -> decimal32_fast
7778
{
7879
decimal32_fast d;
7980
from_chars(str, str + len, d);
8081
return d;
8182
}
8283

83-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char* str, std::size_t len) -> decimal32_fast
84+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char *str, std::size_t len) -> decimal32_fast
8485
{
8586
decimal32_fast d;
8687
from_chars(str, str + len, d);
@@ -89,36 +90,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char* str, std::size_t
8990

9091
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(unsigned long long v) -> decimal32_fast
9192
{
92-
return decimal32_fast{v};
93+
return decimal32_fast {v};
9394
}
9495

9596
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(unsigned long long v) -> decimal32_fast
9697
{
97-
return decimal32_fast{v};
98+
return decimal32_fast {v};
9899
}
99100

100-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char* str) -> decimal64
101+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char *str) -> decimal64
101102
{
102103
decimal64 d;
103104
from_chars(str, str + detail::strlen(str), d);
104105
return d;
105106
}
106107

107-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char* str) -> decimal64
108+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char *str) -> decimal64
108109
{
109110
decimal64 d;
110111
from_chars(str, str + detail::strlen(str), d);
111112
return d;
112113
}
113114

114-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char* str, std::size_t) -> decimal64
115+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char *str, std::size_t) -> decimal64
115116
{
116117
decimal64 d;
117118
from_chars(str, str + detail::strlen(str), d);
118119
return d;
119120
}
120121

121-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char* str, std::size_t) -> decimal64
122+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char *str, std::size_t) -> decimal64
122123
{
123124
decimal64 d;
124125
from_chars(str, str + detail::strlen(str), d);
@@ -127,36 +128,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char* str, std::size_t)
127128

128129
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(unsigned long long v) -> decimal64
129130
{
130-
return decimal64{v};
131+
return decimal64 {v};
131132
}
132133

133134
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(unsigned long long v) -> decimal64
134135
{
135-
return decimal64{v};
136+
return decimal64 {v};
136137
}
137138

138-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char* str) -> decimal64_fast
139+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char *str) -> decimal64_fast
139140
{
140141
decimal64_fast d;
141142
from_chars(str, str + detail::strlen(str), d);
142143
return d;
143144
}
144145

145-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char* str) -> decimal64_fast
146+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char *str) -> decimal64_fast
146147
{
147148
decimal64_fast d;
148149
from_chars(str, str + detail::strlen(str), d);
149150
return d;
150151
}
151152

152-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char* str, std::size_t len) -> decimal64_fast
153+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char *str, std::size_t len) -> decimal64_fast
153154
{
154155
decimal64_fast d;
155156
from_chars(str, str + len, d);
156157
return d;
157158
}
158159

159-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char* str, std::size_t len) -> decimal64_fast
160+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char *str, std::size_t len) -> decimal64_fast
160161
{
161162
decimal64_fast d;
162163
from_chars(str, str + len, d);
@@ -165,36 +166,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char* str, std::size_t
165166

166167
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(unsigned long long v) -> decimal64_fast
167168
{
168-
return decimal64_fast{v};
169+
return decimal64_fast {v};
169170
}
170171

171172
BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(unsigned long long v) -> decimal64_fast
172173
{
173-
return decimal64_fast{v};
174+
return decimal64_fast {v};
174175
}
175176

176-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char* str) -> decimal128
177+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char *str) -> decimal128
177178
{
178179
decimal128 d;
179180
from_chars(str, str + detail::strlen(str), d);
180181
return d;
181182
}
182183

183-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char* str) -> decimal128
184+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char *str) -> decimal128
184185
{
185186
decimal128 d;
186187
from_chars(str, str + detail::strlen(str), d);
187188
return d;
188189
}
189190

190-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char* str, std::size_t) -> decimal128
191+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char *str, std::size_t) -> decimal128
191192
{
192193
decimal128 d;
193194
from_chars(str, str + detail::strlen(str), d);
194195
return d;
195196
}
196197

197-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char* str, std::size_t) -> decimal128
198+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char *str, std::size_t) -> decimal128
198199
{
199200
decimal128 d;
200201
from_chars(str, str + detail::strlen(str), d);
@@ -203,36 +204,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char* str, std::size_t)
203204

204205
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(unsigned long long v) -> decimal128
205206
{
206-
return decimal128{v};
207+
return decimal128 {v};
207208
}
208209

209210
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(unsigned long long v) -> decimal128
210211
{
211-
return decimal128{v};
212+
return decimal128 {v};
212213
}
213214

214-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char* str) -> decimal128_fast
215+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char *str) -> decimal128_fast
215216
{
216217
decimal128_fast d;
217218
from_chars(str, str + detail::strlen(str), d);
218219
return d;
219220
}
220221

221-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char* str) -> decimal128_fast
222+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char *str) -> decimal128_fast
222223
{
223224
decimal128_fast d;
224225
from_chars(str, str + detail::strlen(str), d);
225226
return d;
226227
}
227228

228-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char* str, std::size_t len) -> decimal128_fast
229+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char *str, std::size_t len) -> decimal128_fast
229230
{
230231
decimal128_fast d;
231232
from_chars(str, str + len, d);
232233
return d;
233234
}
234235

235-
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char* str, std::size_t len) -> decimal128_fast
236+
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char *str, std::size_t len) -> decimal128_fast
236237
{
237238
decimal128_fast d;
238239
from_chars(str, str + len, d);
@@ -241,14 +242,15 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char* str, std::size_t
241242

242243
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(unsigned long long v) -> decimal128_fast
243244
{
244-
return decimal128_fast{v};
245+
return decimal128_fast {v};
245246
}
246247

247248
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(unsigned long long v) -> decimal128_fast
248249
{
249-
return decimal128_fast{v};
250+
return decimal128_fast {v};
250251
}
251252

253+
} // namespace literals
252254
} // namespace decimal
253255
} // namespace boost
254256

test/crash_report_1.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88

99
using namespace boost::decimal;
10+
using namespace boost::decimal::literals;
1011

1112
int main()
1213
{

test/test_constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
using namespace boost::decimal;
1010
using namespace boost::decimal::numbers;
11+
using namespace boost::decimal::literals;
1112

1213
template <typename Dec>
1314
void test_constants()

test/test_literals.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <boost/core/lightweight_test.hpp>
99

1010
using namespace boost::decimal;
11+
using namespace boost::decimal::literals;
1112

1213
void test_decimal32_literals()
1314
{

0 commit comments

Comments
 (0)