From f0dfb208e0eef8394c5c0afa8ea97a104755525e Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 7 Apr 2013 21:55:55 +0900 Subject: [PATCH] add _indexes User-defined literals --- sprout/index_tuple/udl.hpp | 67 ++++++++++++++++++++++++++++++++++ sprout/index_tuple/utility.hpp | 1 + sprout/type/string/string.hpp | 14 +++++++ 3 files changed, 82 insertions(+) create mode 100644 sprout/index_tuple/udl.hpp diff --git a/sprout/index_tuple/udl.hpp b/sprout/index_tuple/udl.hpp new file mode 100644 index 00000000..c33d6032 --- /dev/null +++ b/sprout/index_tuple/udl.hpp @@ -0,0 +1,67 @@ +#ifndef SPROUT_INDEX_TUPLE_UDL_HPP +#define SPROUT_INDEX_TUPLE_UDL_HPP + +#include +#include + +#if SPROUT_USE_USER_DEFINED_LITERALS + +#include +#include + +namespace sprout { + namespace detail { + template + struct digits_to_int; + template + struct digits_to_int + : public std::integral_constant + {}; + template + struct digits_to_int + : public std::integral_constant::value> + {}; + } // namespace detail + + // + // indexes_result + // + template + struct indexes_result + : public sprout::make_index_tuple::value> + {}; + // + // uindexes_result + // + template + struct uindexes_result + : public sprout::make_uindex_tuple::value> + {}; + + namespace udl { + // + // _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(); + } + } // namespace udl + + using sprout::udl::operator "" _indexes; + using sprout::udl::operator "" _uindexes; +} // namespace sprout + +#endif // #if SPROUT_USE_USER_DEFINED_LITERALS + +#endif // #ifndef SPROUT_INDEX_TUPLE_UDL_HPP diff --git a/sprout/index_tuple/utility.hpp b/sprout/index_tuple/utility.hpp index 26165edd..40175c56 100644 --- a/sprout/index_tuple/utility.hpp +++ b/sprout/index_tuple/utility.hpp @@ -4,5 +4,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_INDEX_TUPLE_UTILITY_HPP diff --git a/sprout/type/string/string.hpp b/sprout/type/string/string.hpp index 884263c6..91e9eb27 100644 --- a/sprout/type/string/string.hpp +++ b/sprout/type/string/string.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace sprout { namespace types { @@ -47,4 +48,17 @@ namespace std { #endif } // namespace std +namespace sprout { + // + // tuple_get + // + template + inline SPROUT_CONSTEXPR typename std::tuple_element >::type + tuple_get(sprout::types::basic_string) SPROUT_NOEXCEPT { + static_assert(I < sizeof...(Values), "tuple_get: index out of range"); + typedef typename std::tuple_element >::type type; + return type(); + } +} // namespace sprout + #endif // #ifndef SPROUT_TYPE_STRING_STRING_HPP