Skip to content

Commit

Permalink
Merge pull request #809 from cppalliance/literals
Browse files Browse the repository at this point in the history
Move literals into namespace literals
  • Loading branch information
mborland authored Jan 21, 2025
2 parents 069c26a + 0cd5371 commit 234a760
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
2 changes: 2 additions & 0 deletions examples/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <boost/decimal.hpp>
#include <cassert>

using namespace boost::decimal::literals;

template <typename T>
bool float_equal(T lhs, T rhs)
{
Expand Down
74 changes: 38 additions & 36 deletions include/boost/decimal/literals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,30 @@

namespace boost {
namespace decimal {
namespace literals {

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char* str) -> decimal32
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char *str) -> decimal32
{
decimal32 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char* str) -> decimal32
BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char *str) -> decimal32
{
decimal32 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char* str, std::size_t len) -> decimal32
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(const char *str, std::size_t len) -> decimal32
{
decimal32 d;
from_chars(str, str + len, d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char* str, std::size_t len) -> decimal32
BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char *str, std::size_t len) -> decimal32
{
decimal32 d;
from_chars(str, str + len, d);
Expand All @@ -51,36 +52,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(const char* str, std::size_t

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DF(unsigned long long v) -> decimal32
{
return decimal32{v};
return decimal32 {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_df(unsigned long long v) -> decimal32
{
return decimal32{v};
return decimal32 {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char* str) -> decimal32_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char *str) -> decimal32_fast
{
decimal32_fast d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char* str) -> decimal32_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char *str) -> decimal32_fast
{
decimal32_fast d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char* str, std::size_t len) -> decimal32_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(const char *str, std::size_t len) -> decimal32_fast
{
decimal32_fast d;
from_chars(str, str + len, d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char* str, std::size_t len) -> decimal32_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char *str, std::size_t len) -> decimal32_fast
{
decimal32_fast d;
from_chars(str, str + len, d);
Expand All @@ -89,36 +90,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(const char* str, std::size_t

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DFF(unsigned long long v) -> decimal32_fast
{
return decimal32_fast{v};
return decimal32_fast {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dff(unsigned long long v) -> decimal32_fast
{
return decimal32_fast{v};
return decimal32_fast {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char* str) -> decimal64
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char *str) -> decimal64
{
decimal64 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char* str) -> decimal64
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char *str) -> decimal64
{
decimal64 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char* str, std::size_t) -> decimal64
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(const char *str, std::size_t) -> decimal64
{
decimal64 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char* str, std::size_t) -> decimal64
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char *str, std::size_t) -> decimal64
{
decimal64 d;
from_chars(str, str + detail::strlen(str), d);
Expand All @@ -127,36 +128,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(const char* str, std::size_t)

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DD(unsigned long long v) -> decimal64
{
return decimal64{v};
return decimal64 {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dd(unsigned long long v) -> decimal64
{
return decimal64{v};
return decimal64 {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char* str) -> decimal64_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char *str) -> decimal64_fast
{
decimal64_fast d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char* str) -> decimal64_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char *str) -> decimal64_fast
{
decimal64_fast d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char* str, std::size_t len) -> decimal64_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(const char *str, std::size_t len) -> decimal64_fast
{
decimal64_fast d;
from_chars(str, str + len, d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char* str, std::size_t len) -> decimal64_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char *str, std::size_t len) -> decimal64_fast
{
decimal64_fast d;
from_chars(str, str + len, d);
Expand All @@ -165,36 +166,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(const char* str, std::size_t

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DDF(unsigned long long v) -> decimal64_fast
{
return decimal64_fast{v};
return decimal64_fast {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_ddf(unsigned long long v) -> decimal64_fast
{
return decimal64_fast{v};
return decimal64_fast {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char* str) -> decimal128
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char *str) -> decimal128
{
decimal128 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char* str) -> decimal128
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char *str) -> decimal128
{
decimal128 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char* str, std::size_t) -> decimal128
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(const char *str, std::size_t) -> decimal128
{
decimal128 d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char* str, std::size_t) -> decimal128
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char *str, std::size_t) -> decimal128
{
decimal128 d;
from_chars(str, str + detail::strlen(str), d);
Expand All @@ -203,36 +204,36 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(const char* str, std::size_t)

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DL(unsigned long long v) -> decimal128
{
return decimal128{v};
return decimal128 {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dl(unsigned long long v) -> decimal128
{
return decimal128{v};
return decimal128 {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char* str) -> decimal128_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char *str) -> decimal128_fast
{
decimal128_fast d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char* str) -> decimal128_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char *str) -> decimal128_fast
{
decimal128_fast d;
from_chars(str, str + detail::strlen(str), d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char* str, std::size_t len) -> decimal128_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(const char *str, std::size_t len) -> decimal128_fast
{
decimal128_fast d;
from_chars(str, str + len, d);
return d;
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char* str, std::size_t len) -> decimal128_fast
BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char *str, std::size_t len) -> decimal128_fast
{
decimal128_fast d;
from_chars(str, str + len, d);
Expand All @@ -241,14 +242,15 @@ BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(const char* str, std::size_t

BOOST_DECIMAL_EXPORT constexpr auto operator ""_DLF(unsigned long long v) -> decimal128_fast
{
return decimal128_fast{v};
return decimal128_fast {v};
}

BOOST_DECIMAL_EXPORT constexpr auto operator ""_dlf(unsigned long long v) -> decimal128_fast
{
return decimal128_fast{v};
return decimal128_fast {v};
}

} // namespace literals
} // namespace decimal
} // namespace boost

Expand Down
1 change: 1 addition & 0 deletions test/crash_report_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <iostream>

using namespace boost::decimal;
using namespace boost::decimal::literals;

int main()
{
Expand Down
1 change: 1 addition & 0 deletions test/test_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using namespace boost::decimal;
using namespace boost::decimal::numbers;
using namespace boost::decimal::literals;

template <typename Dec>
void test_constants()
Expand Down
1 change: 1 addition & 0 deletions test/test_literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <boost/core/lightweight_test.hpp>

using namespace boost::decimal;
using namespace boost::decimal::literals;

void test_decimal32_literals()
{
Expand Down

0 comments on commit 234a760

Please sign in to comment.