Skip to content

Commit afb9c22

Browse files
committed
Change location of constructor definition for old clangs
1 parent 49fa5d0 commit afb9c22

File tree

2 files changed

+96
-81
lines changed

2 files changed

+96
-81
lines changed

include/boost/decimal/decimal32_t.hpp

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -819,47 +819,6 @@ constexpr decimal32_t::decimal32_t(const T1 coeff, const T2 exp) noexcept : deci
819819

820820
constexpr decimal32_t::decimal32_t(const bool value) noexcept : decimal32_t(static_cast<significand_type>(value), 0, false) {}
821821

822-
#if !defined(BOOST_DECIMAL_DISABLE_CLIB)
823-
824-
constexpr decimal32_t::decimal32_t(const char* str, const std::size_t len)
825-
{
826-
if (str == nullptr || len == 0)
827-
{
828-
bits_ = detail::d32_nan_mask;
829-
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
830-
return; // LCOV_EXCL_LINE
831-
}
832-
833-
// Normally plus signs aren't allowed
834-
auto first {str};
835-
if (*first == '+')
836-
{
837-
++first;
838-
}
839-
840-
decimal32_t v;
841-
const auto r {from_chars(first, str + len, v)};
842-
if (r)
843-
{
844-
*this = v;
845-
}
846-
else
847-
{
848-
bits_ = detail::d32_nan_mask;
849-
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
850-
}
851-
}
852-
853-
constexpr decimal32_t::decimal32_t(const char* str) : decimal32_t(str, detail::strlen(str)) {}
854-
855-
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
856-
inline decimal32_t::decimal32_t(const std::string& str) : decimal32_t(str.c_str(), str.size()) {}
857-
#else
858-
constexpr decimal32_t::decimal32_t(std::string_view str) : decimal32_t(str.data(), str.size()) {}
859-
#endif
860-
861-
#endif // BOOST_DECIMAL_DISABLE_CLIB
862-
863822
constexpr auto from_bits(const std::uint32_t bits) noexcept -> decimal32_t
864823
{
865824
decimal32_t result;
@@ -2389,6 +2348,55 @@ class numeric_limits<boost::decimal::decimal32_t> :
23892348

23902349
} // Namespace std
23912350

2351+
// TODO(mborland): Break charconv up since we only need the from_chars implementation here
2352+
// Probably shouldn't be bringing in everything
23922353
#include <boost/decimal/charconv.hpp>
23932354

2355+
namespace boost {
2356+
namespace decimal {
2357+
2358+
#if !defined(BOOST_DECIMAL_DISABLE_CLIB)
2359+
2360+
constexpr decimal32_t::decimal32_t(const char* str, const std::size_t len)
2361+
{
2362+
if (str == nullptr || len == 0)
2363+
{
2364+
bits_ = detail::d32_nan_mask;
2365+
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
2366+
return; // LCOV_EXCL_LINE
2367+
}
2368+
2369+
// Normally plus signs aren't allowed
2370+
auto first {str};
2371+
if (*first == '+')
2372+
{
2373+
++first;
2374+
}
2375+
2376+
decimal32_t v;
2377+
const auto r {from_chars(first, str + len, v)};
2378+
if (r)
2379+
{
2380+
*this = v;
2381+
}
2382+
else
2383+
{
2384+
bits_ = detail::d32_nan_mask;
2385+
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
2386+
}
2387+
}
2388+
2389+
constexpr decimal32_t::decimal32_t(const char* str) : decimal32_t(str, detail::strlen(str)) {}
2390+
2391+
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
2392+
inline decimal32_t::decimal32_t(const std::string& str) : decimal32_t(str.c_str(), str.size()) {}
2393+
#else
2394+
constexpr decimal32_t::decimal32_t(std::string_view str) : decimal32_t(str.data(), str.size()) {}
2395+
#endif
2396+
2397+
#endif // BOOST_DECIMAL_DISABLE_CLIB
2398+
2399+
} // namespace decimal
2400+
} // namespace boost
2401+
23942402
#endif // BOOST_DECIMAL_decimal32_t_HPP

include/boost/decimal/decimal64_t.hpp

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -913,46 +913,6 @@ constexpr auto decimal64_t::operator=(const Integer& val) noexcept
913913
return *this;
914914
}
915915

916-
#if !defined(BOOST_DECIMAL_DISABLE_CLIB)
917-
constexpr decimal64_t::decimal64_t(const char* str, std::size_t len)
918-
{
919-
if (str == nullptr || len == 0)
920-
{
921-
bits_ = detail::d64_nan_mask;
922-
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
923-
return; // LCOV_EXCL_LINE
924-
}
925-
926-
// Normally plus signs aren't allowed
927-
auto first {str};
928-
if (*first == '+')
929-
{
930-
++first;
931-
}
932-
933-
decimal64_t v;
934-
const auto r {from_chars(first, str + len, v)};
935-
if (r)
936-
{
937-
*this = v;
938-
}
939-
else
940-
{
941-
bits_ = detail::d64_nan_mask;
942-
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
943-
}
944-
}
945-
946-
constexpr decimal64_t::decimal64_t(const char* str) : decimal64_t(str, detail::strlen(str)) {}
947-
948-
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
949-
inline decimal64_t::decimal64_t(const std::string& str) : decimal64_t(str.c_str(), str.size()) {}
950-
#else
951-
constexpr decimal64_t::decimal64_t(std::string_view str) : decimal64_t(str.data(), str.size()) {}
952-
#endif
953-
954-
#endif // BOOST_DECIMAL_DISABLE_CLIB
955-
956916
constexpr decimal64_t::operator bool() const noexcept
957917
{
958918
constexpr decimal64_t zero {0, 0};
@@ -2299,4 +2259,51 @@ class numeric_limits<boost::decimal::decimal64_t> :
22992259

23002260
#include <boost/decimal/charconv.hpp>
23012261

2262+
namespace boost {
2263+
namespace decimal {
2264+
2265+
#if !defined(BOOST_DECIMAL_DISABLE_CLIB)
2266+
2267+
constexpr decimal64_t::decimal64_t(const char* str, std::size_t len)
2268+
{
2269+
if (str == nullptr || len == 0)
2270+
{
2271+
bits_ = detail::d64_nan_mask;
2272+
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
2273+
return; // LCOV_EXCL_LINE
2274+
}
2275+
2276+
// Normally plus signs aren't allowed
2277+
auto first {str};
2278+
if (*first == '+')
2279+
{
2280+
++first;
2281+
}
2282+
2283+
decimal64_t v;
2284+
const auto r {from_chars(first, str + len, v)};
2285+
if (r)
2286+
{
2287+
*this = v;
2288+
}
2289+
else
2290+
{
2291+
bits_ = detail::d64_nan_mask;
2292+
BOOST_DECIMAL_THROW_EXCEPTION(std::runtime_error("Can not construct from invalid string"));
2293+
}
2294+
}
2295+
2296+
constexpr decimal64_t::decimal64_t(const char* str) : decimal64_t(str, detail::strlen(str)) {}
2297+
2298+
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
2299+
inline decimal64_t::decimal64_t(const std::string& str) : decimal64_t(str.c_str(), str.size()) {}
2300+
#else
2301+
constexpr decimal64_t::decimal64_t(std::string_view str) : decimal64_t(str.data(), str.size()) {}
2302+
#endif
2303+
2304+
#endif // BOOST_DECIMAL_DISABLE_CLIB
2305+
2306+
} // namespace decimal
2307+
} // namespace boost
2308+
23022309
#endif //BOOST_DECIMAL_decimal64_t_HPP

0 commit comments

Comments
 (0)