add type_traits/aliases.hpp

This commit is contained in:
bolero-MURAKAMI 2012-05-26 19:19:08 +09:00
parent dacba801a6
commit eaea3771fc
8 changed files with 153 additions and 36 deletions

View file

@ -29,6 +29,7 @@ namespace sprout {
return sprout::llabs(j);
}
namespace {
template<
typename IntType,
typename sprout::enabler_if<
@ -47,6 +48,7 @@ namespace sprout {
SPROUT_CONSTEXPR IntType abs(IntType j) {
return j;
}
} // anonymous-namespace
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_ABS_HPP

View file

@ -2,7 +2,6 @@
#define SPROUT_STRING_ALIAS_HPP
#include <sprout/config.hpp>
#if SPROUT_USE_TEMPLATE_ALIASES
# include <cstddef>
# include <sprout/string/string.hpp>

View file

@ -8,6 +8,9 @@
#include <sprout/type_traits/is_c_str.hpp>
#include <sprout/type_traits/lvalue_reference.hpp>
#include <sprout/type_traits/const_reference.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/type_traits/has_xxx.hpp>
#include <sprout/type_traits/inherit_if_xxx.hpp>
#include <sprout/type_traits/aliases.hpp>
#endif // #ifndef SPROUT_TYPE_TRAITS_HPP

View file

@ -0,0 +1,91 @@
#ifndef SPROUT_TYPE_TRAITS_ALIASES_HPP
#define SPROUT_TYPE_TRAITS_ALIASES_HPP
#include <sprout/config.hpp>
#if SPROUT_USE_TEMPLATE_ALIASES
# include <cstddef>
# include <type_traits>
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
namespace sprout {
#if SPROUT_USE_TEMPLATE_ALIASES
// Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/
//
// Const-volatility specifiers
//
template<typename T>
using remove_const_ = typename std::remove_const<T>::type;
template<typename T>
using remove_volatile_ = typename std::remove_volatile<T>::type;
template<typename T>
using remove_cv_ = typename std::remove_cv<T>::type;
template<typename T>
using add_const_ = typename std::add_const<T>::type;
template<typename T>
using add_volatile_ = typename std::add_volatile<T>::type;
template<typename T>
using add_cv_ = typename std::add_cv<T>::type;
//
// References
//
template<typename T>
using remove_reference_ = typename std::remove_reference<T>::type;
template<typename T>
using add_lvalue_reference_ = typename std::add_lvalue_reference<T>::type;
template<typename T>
using add_rvalue_reference_ = typename std::add_rvalue_reference<T>::type;
//
// Pointers
//
template<typename T>
using remove_pointer_ = typename std::remove_pointer<T>::type;
template<typename T>
using add_pointer_ = typename std::add_pointer<T>::type;
//
// Sign modifiers
//
template<typename T>
using make_signed_ = typename std::make_signed<T>::type;
template<typename T>
using make_unsigned_ = typename std::make_unsigned<T>::type;
//
// Arrays
//
template<typename T>
using remove_extent_ = typename std::remove_extent<T>::type;
template<typename T>
using remove_all_extents_ = typename std::remove_all_extents<T>::type;
//
// Miscellaneous transformations
//
template<
std::size_t Len,
std::size_t Align = std::alignment_of<typename std::aligned_storage<Len>::type>::value
>
using aligned_storage_ = typename std::aligned_storage<Len, Align>::type;
// !!!
//template<std::size_t Len, typename... Types>
//using aligned_union_ = typename std::aligned_union<Len, Types...>::type;
template<typename T>
using decay_ = typename std::decay<T>::type;
template<bool B, typename T = void>
using enable_if_ = typename std::enable_if<B, T>::type;
template<bool B, typename T, typename F>
using conditional_ = typename std::conditional<B, T, F>::type;
template<typename... Types>
using common_type_ = typename std::common_type<Types...>::type;
template<typename T>
using underlying_type_ = typename std::underlying_type<T>::type;
template<typename F, typename... ArgTypes>
using result_of_ = typename std::result_of<F(ArgTypes...)>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_ALIASES_HPP

View file

@ -14,6 +14,11 @@ namespace sprout {
public:
typedef decltype(sprout::as_const(std::declval<T&&>())) type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using const_reference_ = typename sprout::const_reference<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_CONST_REFERENCE_HPP

View file

@ -0,0 +1,28 @@
#ifndef SPROUT_TYPE_TRAITS_ENABLER_IF_HPP
#define SPROUT_TYPE_TRAITS_ENABLER_IF_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
//
// enabler_t
// enabler
//
typedef void* enabler_t;
extern enabler_t enabler;
//
// enabler_if
//
template<bool C>
class enabler_if
: public std::enable_if<C, sprout::enabler_t&>
{};
#if SPROUT_USE_TEMPLATE_ALIASES
template<bool C>
using enabler_if_ = typename sprout::enabler_if<C>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_ENABLER_IF_HPP

View file

@ -14,6 +14,11 @@ namespace sprout {
public:
typedef decltype(sprout::as_lvalue(std::declval<T&&>())) type;
};
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using lvalue_reference_ = typename sprout::lvalue_reference<T>::type;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_LVALUE_REFERENCE_HPP

View file

@ -1,23 +1,7 @@
#ifndef SPROUT_UTILITY_ENABLER_IF_HPP
#define SPROUT_UTILITY_ENABLER_IF_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
//
// enabler_t
// enabler
//
typedef void* enabler_t;
extern enabler_t enabler;
//
// enabler_if
//
template<bool C>
class enabler_if
: public std::enable_if<C, enabler_t&>
{};
} // namespace sprout
#include <sprout/type_traits/enabler_if.hpp>
#endif // #ifndef SPROUT_UTILITY_ENABLER_IF_HPP