From 94b146b5cc608e124349ce169fb2f611db552b73 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 14 Apr 2013 16:51:19 +0900 Subject: [PATCH] add user-defined literals complex, rational --- sprout/assert.hpp | 4 +-- sprout/complex.hpp | 1 + sprout/complex/udl.hpp | 63 ++++++++++++++++++++++++++++++++++++++ sprout/index_tuple/udl.hpp | 41 ++++++++++++++----------- sprout/rational.hpp | 1 + sprout/rational/udl.hpp | 63 ++++++++++++++++++++++++++++++++++++++ sprout/uuid/udl.hpp | 20 ++++++++---- 7 files changed, 167 insertions(+), 26 deletions(-) create mode 100644 sprout/complex/udl.hpp create mode 100644 sprout/rational/udl.hpp diff --git a/sprout/assert.hpp b/sprout/assert.hpp index af5c1855..ecda2e02 100644 --- a/sprout/assert.hpp +++ b/sprout/assert.hpp @@ -69,7 +69,7 @@ namespace sprout { // void assertion_failed(sprout::assertion_info const&); -} // namespace sprout_adl +} // namespace sprout namespace sprout { namespace detail { @@ -166,7 +166,7 @@ namespace sprout { // void assertion_failed_msg(sprout::assertion_info_msg const&); -} // namespace sprout_adl +} // namespace sprout namespace sprout { namespace detail { diff --git a/sprout/complex.hpp b/sprout/complex.hpp index a61c0f41..f8e6a706 100644 --- a/sprout/complex.hpp +++ b/sprout/complex.hpp @@ -8,5 +8,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_COMPLEX_HPP diff --git a/sprout/complex/udl.hpp b/sprout/complex/udl.hpp new file mode 100644 index 00000000..f9b05704 --- /dev/null +++ b/sprout/complex/udl.hpp @@ -0,0 +1,63 @@ +#ifndef SPROUT_COMPLEX_UDL_HPP +#define SPROUT_COMPLEX_UDL_HPP + +#include +#include + +#if SPROUT_USE_USER_DEFINED_LITERALS + +namespace sprout { + namespace udl { + namespace complex { + // + // _i + // + inline SPROUT_CONSTEXPR sprout::complex + operator"" _i(long double x) { + return sprout::complex(0, x); + } + + // + // _if + // _iF + // + inline SPROUT_CONSTEXPR sprout::complex + operator"" _if(long double x) { + return sprout::complex(0, x); + } + inline SPROUT_CONSTEXPR sprout::complex + operator"" _iF(long double x) { + return sprout::complex(0, x); + } + + // + // _il + // _iL + // + inline SPROUT_CONSTEXPR sprout::complex + operator"" _il(long double x) { + return sprout::complex(0, x); + } + inline SPROUT_CONSTEXPR sprout::complex + operator"" _iL(long double x) { + return sprout::complex(0, x); + } + } // namespace complex + + using sprout::udl::complex::operator"" _i; + using sprout::udl::complex::operator"" _if; + using sprout::udl::complex::operator"" _iF; + using sprout::udl::complex::operator"" _il; + using sprout::udl::complex::operator"" _iL; + } // namespace udl + + using sprout::udl::complex::operator"" _i; + using sprout::udl::complex::operator"" _if; + using sprout::udl::complex::operator"" _iF; + using sprout::udl::complex::operator"" _il; + using sprout::udl::complex::operator"" _iL; +} // namespace sprout + +#endif // #if SPROUT_USE_USER_DEFINED_LITERALS + +#endif // #ifndef SPROUT_COMPLEX_UDL_HPP diff --git a/sprout/index_tuple/udl.hpp b/sprout/index_tuple/udl.hpp index c33d6032..aafdc9db 100644 --- a/sprout/index_tuple/udl.hpp +++ b/sprout/index_tuple/udl.hpp @@ -39,27 +39,32 @@ namespace sprout { {}; namespace udl { - // - // _indexes - // - template - SPROUT_CONSTEXPR typename sprout::indexes_result::type - operator "" _indexes() { - return sprout::indexes_result::make(); - } + namespace indexes { + // + // _indexes + // + template + SPROUT_CONSTEXPR typename sprout::indexes_result::type + operator"" _indexes() { + return sprout::indexes_result::make(); + } - // - // _uindexes - // - template - SPROUT_CONSTEXPR typename sprout::uindexes_result::type - operator "" _uindexes() { - return sprout::uindexes_result::make(); - } + // + // _uindexes + // + template + SPROUT_CONSTEXPR typename sprout::uindexes_result::type + operator"" _uindexes() { + return sprout::uindexes_result::make(); + } + } // namespace indexes + + using sprout::udl::indexes::operator"" _indexes; + using sprout::udl::indexes::operator"" _uindexes; } // namespace udl - using sprout::udl::operator "" _indexes; - using sprout::udl::operator "" _uindexes; + using sprout::udl::indexes::operator"" _indexes; + using sprout::udl::indexes::operator"" _uindexes; } // namespace sprout #endif // #if SPROUT_USE_USER_DEFINED_LITERALS diff --git a/sprout/rational.hpp b/sprout/rational.hpp index 199ae797..b28d7c08 100644 --- a/sprout/rational.hpp +++ b/sprout/rational.hpp @@ -10,5 +10,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_RATIONAL_HPP diff --git a/sprout/rational/udl.hpp b/sprout/rational/udl.hpp new file mode 100644 index 00000000..407d8db8 --- /dev/null +++ b/sprout/rational/udl.hpp @@ -0,0 +1,63 @@ +#ifndef SPROUT_RATIONAL_UDL_HPP +#define SPROUT_RATIONAL_UDL_HPP + +#include +#include + +#if SPROUT_USE_USER_DEFINED_LITERALS + +namespace sprout { + namespace udl { + namespace rational { + // + // _r + // + inline SPROUT_CONSTEXPR sprout::rational + operator"" _r(unsigned long long x) { + return sprout::rational(x); + } + + // + // _rl + // _rL + // + inline SPROUT_CONSTEXPR sprout::rational + operator"" _rl(unsigned long long x) { + return sprout::rational(x); + } + inline SPROUT_CONSTEXPR sprout::rational + operator"" _rL(unsigned long long x) { + return sprout::rational(x); + } + + // + // _rll + // _rLL + // + inline SPROUT_CONSTEXPR sprout::rational + operator"" _rll(unsigned long long x) { + return sprout::rational(x); + } + inline SPROUT_CONSTEXPR sprout::rational + operator"" _rLL(unsigned long long x) { + return sprout::rational(x); + } + } // namespace rational + + using sprout::udl::rational::operator"" _r; + using sprout::udl::rational::operator"" _rl; + using sprout::udl::rational::operator"" _rL; + using sprout::udl::rational::operator"" _rll; + using sprout::udl::rational::operator"" _rLL; + } // namespace udl + + using sprout::udl::rational::operator"" _r; + using sprout::udl::rational::operator"" _rl; + using sprout::udl::rational::operator"" _rL; + using sprout::udl::rational::operator"" _rll; + using sprout::udl::rational::operator"" _rLL; +} // namespace sprout + +#endif // #if SPROUT_USE_USER_DEFINED_LITERALS + +#endif // #ifndef SPROUT_RATIONAL_UDL_HPP diff --git a/sprout/uuid/udl.hpp b/sprout/uuid/udl.hpp index a32ae559..800d9c1f 100644 --- a/sprout/uuid/udl.hpp +++ b/sprout/uuid/udl.hpp @@ -16,27 +16,35 @@ namespace sprout { // _uuid // inline SPROUT_CONSTEXPR sprout::uuids::uuid - operator "" _uuid(char const* s, std::size_t size) { + operator"" _uuid(char const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } inline SPROUT_CONSTEXPR sprout::uuids::uuid - operator "" _uuid(wchar_t const* s, std::size_t size) { + operator"" _uuid(wchar_t const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } inline SPROUT_CONSTEXPR sprout::uuids::uuid - operator "" _uuid(char16_t const* s, std::size_t size) { + operator"" _uuid(char16_t const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } inline SPROUT_CONSTEXPR sprout::uuids::uuid - operator "" _uuid(char32_t const* s, std::size_t size) { + operator"" _uuid(char32_t const* s, std::size_t size) { return sprout::uuids::string_generator()(s, s + size); } + } // namespace udl + + using sprout::uuids::udl::operator"" _uuid; + } // namespace uuids + + namespace udl { + namespace uuids { + using sprout::uuids::udl::operator"" _uuid; } // namespace uuids - using sprout::uuids::udl::operator "" _uuid; + using sprout::uuids::udl::operator"" _uuid; } // namespace udl - using sprout::uuids::udl::operator "" _uuid; + using sprout::uuids::udl::operator"" _uuid; } // namespace sprout #endif // #if SPROUT_USE_USER_DEFINED_LITERALS