add _ placeholder User-defined literals

This commit is contained in:
bolero-MURAKAMI 2013-07-07 19:10:25 +09:00
parent 50f2ba6e31
commit 2f86a59273
7 changed files with 188 additions and 116 deletions

View file

@ -0,0 +1,22 @@
#ifndef SPROUT_DETAIL_DIGITS_TO_INT_HPP
#define SPROUT_DETAIL_DIGITS_TO_INT_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace detail {
template<typename IntType, char... Chars>
struct digits_to_int;
template<typename IntType, char C>
struct digits_to_int<IntType, C>
: public std::integral_constant<IntType, IntType(C - 48)>
{};
template<typename IntType, char Head, char... Tail>
struct digits_to_int<IntType, Head, Tail...>
: public std::integral_constant<IntType, 10 * IntType(Head - 48) + sprout::detail::digits_to_int<IntType, Tail...>::value>
{};
} // namespace detail
} // namespace sprout
#endif // #ifndef SPROUT_DETAIL_DIGITS_TO_INT_HPP

View file

@ -3,5 +3,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/bind/bind.hpp> #include <sprout/functional/bind/bind.hpp>
#include <sprout/functional/bind/placeholder.hpp>
#include <sprout/functional/bind/udl.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_BIND_HPP #endif // #ifndef SPROUT_FUNCTIONAL_BIND_HPP

View file

@ -15,10 +15,14 @@
#include <sprout/functional/ref.hpp> #include <sprout/functional/ref.hpp>
#include <sprout/functional/mem_fn.hpp> #include <sprout/functional/mem_fn.hpp>
#include <sprout/functional/type_traits/weak_result_type.hpp> #include <sprout/functional/type_traits/weak_result_type.hpp>
#include <sprout/functional/bind/placeholder.hpp>
namespace sprout { namespace sprout {
// 20.8.9 bind // 20.8.9 bind
//
// is_bind_expression
//
template<typename T> template<typename T>
struct is_bind_expression struct is_bind_expression
: public std::false_type : public std::false_type
@ -36,99 +40,6 @@ namespace sprout {
: public sprout::is_bind_expression<T> : public sprout::is_bind_expression<T>
{}; {};
template<typename T>
struct is_placeholder
: public std::integral_constant<int, 0>
{};
template<typename T>
struct is_placeholder<T const>
: public sprout::is_placeholder<T>
{};
template<typename T>
struct is_placeholder<T volatile>
: public sprout::is_placeholder<T>
{};
template<typename T>
struct is_placeholder<T const volatile>
: public sprout::is_placeholder<T>
{};
//
// placeholder
//
template<int N>
struct placeholder {};
namespace placeholders {
namespace {
SPROUT_STATIC_CONSTEXPR sprout::placeholder<1> _1 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<2> _2 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<3> _3 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<4> _4 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<5> _5 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<6> _6 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<7> _7 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<8> _8 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<9> _9 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<10> _10 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<11> _11 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<12> _12 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<13> _13 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<14> _14 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<15> _15 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<16> _16 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<17> _17 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<18> _18 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<19> _19 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<20> _20 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<21> _21 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<22> _22 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<23> _23 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<24> _24 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<25> _25 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<26> _26 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<27> _27 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<28> _28 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<29> _29 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<30> _30 = {};
} // anonymous-namespace
} // namespace placeholders
using sprout::placeholders::_1;
using sprout::placeholders::_2;
using sprout::placeholders::_3;
using sprout::placeholders::_4;
using sprout::placeholders::_5;
using sprout::placeholders::_6;
using sprout::placeholders::_7;
using sprout::placeholders::_8;
using sprout::placeholders::_9;
using sprout::placeholders::_10;
using sprout::placeholders::_11;
using sprout::placeholders::_12;
using sprout::placeholders::_13;
using sprout::placeholders::_14;
using sprout::placeholders::_15;
using sprout::placeholders::_16;
using sprout::placeholders::_17;
using sprout::placeholders::_18;
using sprout::placeholders::_19;
using sprout::placeholders::_20;
using sprout::placeholders::_21;
using sprout::placeholders::_2;
using sprout::placeholders::_23;
using sprout::placeholders::_24;
using sprout::placeholders::_25;
using sprout::placeholders::_26;
using sprout::placeholders::_27;
using sprout::placeholders::_28;
using sprout::placeholders::_29;
using sprout::placeholders::_30;
template<int N>
struct is_placeholder<sprout::placeholder<N> >
: public std::integral_constant<int, N>
{};
namespace detail { namespace detail {
struct no_tuple_element; struct no_tuple_element;
@ -509,6 +420,9 @@ namespace sprout {
} }
}; };
//
// is_bind_expression
//
template<typename Signature> template<typename Signature>
struct is_bind_expression<sprout::binder<Signature> > struct is_bind_expression<sprout::binder<Signature> >
: public std::true_type : public std::true_type

View file

@ -0,0 +1,104 @@
#ifndef SPROUT_FUNCTIONAL_BIND_PLACEHOLDER_HPP
#define SPROUT_FUNCTIONAL_BIND_PLACEHOLDER_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
//
// placeholder
//
template<int N>
struct placeholder {};
namespace placeholders {
namespace {
SPROUT_STATIC_CONSTEXPR sprout::placeholder<1> _1 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<2> _2 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<3> _3 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<4> _4 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<5> _5 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<6> _6 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<7> _7 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<8> _8 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<9> _9 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<10> _10 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<11> _11 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<12> _12 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<13> _13 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<14> _14 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<15> _15 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<16> _16 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<17> _17 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<18> _18 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<19> _19 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<20> _20 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<21> _21 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<22> _22 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<23> _23 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<24> _24 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<25> _25 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<26> _26 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<27> _27 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<28> _28 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<29> _29 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<30> _30 = {};
} // anonymous-namespace
} // namespace placeholders
using sprout::placeholders::_1;
using sprout::placeholders::_2;
using sprout::placeholders::_3;
using sprout::placeholders::_4;
using sprout::placeholders::_5;
using sprout::placeholders::_6;
using sprout::placeholders::_7;
using sprout::placeholders::_8;
using sprout::placeholders::_9;
using sprout::placeholders::_10;
using sprout::placeholders::_11;
using sprout::placeholders::_12;
using sprout::placeholders::_13;
using sprout::placeholders::_14;
using sprout::placeholders::_15;
using sprout::placeholders::_16;
using sprout::placeholders::_17;
using sprout::placeholders::_18;
using sprout::placeholders::_19;
using sprout::placeholders::_20;
using sprout::placeholders::_21;
using sprout::placeholders::_2;
using sprout::placeholders::_23;
using sprout::placeholders::_24;
using sprout::placeholders::_25;
using sprout::placeholders::_26;
using sprout::placeholders::_27;
using sprout::placeholders::_28;
using sprout::placeholders::_29;
using sprout::placeholders::_30;
//
// is_placeholder
//
template<typename T>
struct is_placeholder
: public std::integral_constant<int, 0>
{};
template<typename T>
struct is_placeholder<T const>
: public sprout::is_placeholder<T>
{};
template<typename T>
struct is_placeholder<T volatile>
: public sprout::is_placeholder<T>
{};
template<typename T>
struct is_placeholder<T const volatile>
: public sprout::is_placeholder<T>
{};
template<int N>
struct is_placeholder<sprout::placeholder<N> >
: public std::integral_constant<int, N>
{};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_BIND_PLACEHOLDER_HPP

View file

@ -0,0 +1,48 @@
#ifndef SPROUT_FUNCTIONAL_BIND_UDL_HPP
#define SPROUT_FUNCTIONAL_BIND_UDL_HPP
#include <sprout/config.hpp>
#include <sprout/functional/bind/placeholder.hpp>
#if SPROUT_USE_USER_DEFINED_LITERALS
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/digits_to_int.hpp>
namespace sprout {
//
// placeholders_result
//
template<char... Chars>
struct placeholders_result
: public sprout::identity<
sprout::placeholder<sprout::detail::digits_to_int<int, Chars...>::value>
>
{};
namespace placeholders {
namespace udl {
//
// _
//
template<char... Chars>
SPROUT_CONSTEXPR typename sprout::placeholders_result<Chars...>::type
operator"" _() {
typedef typename sprout::placeholders_result<Chars...>::type type;
return type();
}
} // namespace udl
} // namespace placeholders
namespace udl {
namespace placeholders {
using sprout::placeholders::udl::operator"" _;
} // namespace placeholders
using sprout::placeholders::udl::operator"" _;
} // namespace udl
} // namespace sprout
#endif // #if SPROUT_USE_USER_DEFINED_LITERALS
#endif // #ifndef SPROUT_FUNCTIONAL_BIND_UDL_HPP

View file

@ -161,7 +161,7 @@ namespace sprout {
// invocation // invocation
template<typename... Args> template<typename... Args>
SPROUT_CONSTEXPR typename std::result_of<T& (Args&&...)>::type SPROUT_CONSTEXPR typename std::result_of<T& (Args&&...)>::type
operator() (Args&&... args) const { operator()(Args&&... args) const {
return (*t_)(sprout::forward<Args>(args)...); return (*t_)(sprout::forward<Args>(args)...);
} }
}; };
@ -285,7 +285,7 @@ namespace sprout {
// unwrap_ref // unwrap_ref
// //
template<typename T> template<typename T>
inline typename sprout::unwrap_reference<T>::type& inline SPROUT_CONSTEXPR typename sprout::unwrap_reference<T>::type&
unwrap_ref(T& t) { unwrap_ref(T& t) {
return t; return t;
} }

View file

@ -6,33 +6,18 @@
#if SPROUT_USE_USER_DEFINED_LITERALS #if SPROUT_USE_USER_DEFINED_LITERALS
#include <type_traits>
#include <sprout/index_tuple/make_index_tuple.hpp> #include <sprout/index_tuple/make_index_tuple.hpp>
#include <sprout/detail/digits_to_int.hpp>
namespace sprout { namespace sprout {
namespace detail {
template<typename IntType, char... Chars>
struct digits_to_int;
template<typename IntType, char C>
struct digits_to_int<IntType, C>
: public std::integral_constant<IntType, IntType(C - 48)>
{};
template<typename IntType, char Head, char... Tail>
struct digits_to_int<IntType, Head, Tail...>
: public std::integral_constant<IntType, 10 * IntType(Head - 48) + sprout::detail::digits_to_int<IntType, Tail...>::value>
{};
} // namespace detail
// //
// indexes_result // indexes_result
// uindexes_result
// //
template<char... Chars> template<char... Chars>
struct indexes_result struct indexes_result
: public sprout::make_index_tuple<sprout::detail::digits_to_int<sprout::index_t, Chars...>::value> : public sprout::make_index_tuple<sprout::detail::digits_to_int<sprout::index_t, Chars...>::value>
{}; {};
//
// uindexes_result
//
template<char... Chars> template<char... Chars>
struct uindexes_result struct uindexes_result
: public sprout::make_uindex_tuple<sprout::detail::digits_to_int<sprout::uindex_t, Chars...>::value> : public sprout::make_uindex_tuple<sprout::detail::digits_to_int<sprout::uindex_t, Chars...>::value>
@ -42,16 +27,13 @@ namespace sprout {
namespace indexes { namespace indexes {
// //
// _indexes // _indexes
// _uindexes
// //
template<char... Chars> template<char... Chars>
SPROUT_CONSTEXPR typename sprout::indexes_result<Chars...>::type SPROUT_CONSTEXPR typename sprout::indexes_result<Chars...>::type
operator"" _indexes() { operator"" _indexes() {
return sprout::indexes_result<Chars...>::make(); return sprout::indexes_result<Chars...>::make();
} }
//
// _uindexes
//
template<char... Chars> template<char... Chars>
SPROUT_CONSTEXPR typename sprout::uindexes_result<Chars...>::type SPROUT_CONSTEXPR typename sprout::uindexes_result<Chars...>::type
operator"" _uindexes() { operator"" _uindexes() {