From d7fbadb62cf4999d6b8af11f4bbd842a9d1f3d76 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 18 Mar 2012 22:04:09 +0900 Subject: [PATCH] add User defined literal sprout::uuids::udl::_uuid fix sprout::uuid::string_generator --- sprout/auto_config.hpp | 4 ++++ sprout/config.hpp | 6 +++++ sprout/uuid.hpp | 1 + sprout/uuid/string_generator.hpp | 8 +++---- sprout/uuid/udl.hpp | 40 ++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 sprout/uuid/udl.hpp diff --git a/sprout/auto_config.hpp b/sprout/auto_config.hpp index cfb54dda..268962ee 100644 --- a/sprout/auto_config.hpp +++ b/sprout/auto_config.hpp @@ -39,6 +39,10 @@ # endif // #ifdef BOOST_NO_TEMPLATE_ALIASES #endif // #ifndef SPROUT_CONFIG_DISABLE_TEMPLATE_ALIASES +// +// SPROUT_USE_USER_DEFINED_LITERALS +// + // // SPROUT_CONFIG_USE_SSCRISK_CEL // diff --git a/sprout/config.hpp b/sprout/config.hpp index b22aa4ee..55a57a65 100644 --- a/sprout/config.hpp +++ b/sprout/config.hpp @@ -23,6 +23,12 @@ # define SPROUT_USE_TEMPLATE_ALIASES 0 #endif // #ifndef SPROUT_CONFIG_DISABLE_TEMPLATE_ALIASES +#ifndef SPROUT_CONFIG_DISABLE_USER_DEFINED_LITERALS +# define SPROUT_USE_USER_DEFINED_LITERALS 1 +#else // #ifndef SPROUT_CONFIG_DISABLE_USER_DEFINED_LITERALS +# define SPROUT_USE_USER_DEFINED_LITERALS 0 +#endif // #ifndef SPROUT_CONFIG_DISABLE_USER_DEFINED_LITERALS + #ifndef SPROUT_CONFIG_USE_SSCRISK_CEL # define HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT_DETAIL # define HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL diff --git a/sprout/uuid.hpp b/sprout/uuid.hpp index dc212f4b..14267ba3 100644 --- a/sprout/uuid.hpp +++ b/sprout/uuid.hpp @@ -6,5 +6,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_UUID_HPP diff --git a/sprout/uuid/string_generator.hpp b/sprout/uuid/string_generator.hpp index a6d7d4e3..df9d6b36 100644 --- a/sprout/uuid/string_generator.hpp +++ b/sprout/uuid/string_generator.hpp @@ -168,6 +168,10 @@ namespace sprout { ; } public: + template + SPROUT_CONSTEXPR result_type operator()(Iterator first, Iterator last) const { + return generate_1(next_char(first, last)); + } template SPROUT_CONSTEXPR result_type operator()(sprout::basic_string const& s) const { return operator()(s.begin(), s.end()); @@ -184,10 +188,6 @@ namespace sprout { SPROUT_CONSTEXPR result_type operator()(char32_t const* s) const { return operator()(s, s + sprout::char_traits::length(s)); } - template - SPROUT_CONSTEXPR result_type operator()(Iterator first, Iterator last) const { - return generate_1(next_char(first, last)); - } }; } // namespace uuids } // namespace sprout diff --git a/sprout/uuid/udl.hpp b/sprout/uuid/udl.hpp new file mode 100644 index 00000000..0d11c924 --- /dev/null +++ b/sprout/uuid/udl.hpp @@ -0,0 +1,40 @@ +#ifndef SPROUT_UUID_UDL_HPP +#define SPROUT_UUID_UDL_HPP + +#include +#include + +#if SPROUT_USE_USER_DEFINED_LITERALS + +#include +#include + +namespace sprout { + namespace uuids { + namespace udl { + // + // _uuid + // + SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(char const* s, std::size_t) { + return sprout::uuids::string_generator()(s); + } + SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(wchar_t const* s, std::size_t) { + return sprout::uuids::string_generator()(s); + } + SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(char16_t const* s, std::size_t) { + return sprout::uuids::string_generator()(s); + } + SPROUT_CONSTEXPR sprout::uuids::uuid operator "" _uuid(char32_t const* s, std::size_t) { + return sprout::uuids::string_generator()(s); + } + } // namespace uuids + + using sprout::uuids::udl::operator "" _uuid; + } // namespace udl + + using sprout::uuids::udl::operator "" _uuid; +} // namespace sprout + +#endif // #if SPROUT_USE_USER_DEFINED_LITERALS + +#endif // #ifndef SPROUT_UUID_UDL_HPP