1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

sprout/weed.hpp 追加

This commit is contained in:
bolero-MURAKAMI 2011-11-13 17:54:38 +09:00
parent 8103682fdb
commit ecfc2b297a
96 changed files with 5127 additions and 0 deletions

View file

@ -0,0 +1,22 @@
#ifndef SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP
#define SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T>
struct c_str_as_string;
template<typename T, std::size_t N>
struct c_str_as_string<T const[N]> {
public:
typedef sprout::basic_string<T, N - 1> type;
};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP
#define SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_both_tuple
: public std::false_type
{};
template<typename T, typename U>
struct is_both_tuple<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_tuple<T>::value
&& sprout::weed::traits::is_tuple<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP
#define SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_both_unused
: public std::false_type
{};
template<typename T, typename U>
struct is_both_unused<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_unused<T>::value
&& sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP

View file

@ -0,0 +1,33 @@
#ifndef SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_container_and_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_container_and_elem<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_container<T>::value
&& std::is_same<
typename T::value_type,
U
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_tuple_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_different_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_different_elem<
T,
U,
typename std::enable_if<
!std::is_same<T, U>::value
&& !is_same_container<T, U>::value
&& !is_container_and_elem<T, U>::value
&& !is_elem_and_container<T, U>::value
&& !is_both_tuple<T, U>::value
&& !is_tuple_and_elem<T, U>::value
&& !is_elem_and_tuple<T, U>::value
&& !sprout::weed::traits::is_unused<T>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP

View file

@ -0,0 +1,33 @@
#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP
#define SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_elem_and_container
: public std::false_type
{};
template<typename T, typename U>
struct is_elem_and_container<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_container<U>::value
&& std::is_same<
typename U::value_type,
T
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP
#define SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_tuple.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_elem_and_tuple
: public std::false_type
{};
template<typename T, typename U>
struct is_elem_and_tuple<
T,
U,
typename std::enable_if<
!sprout::weed::traits::is_tuple<T>::value
&& !sprout::weed::traits::is_unused<T>::value
&& sprout::weed::traits::is_tuple<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP
#define SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_elem_and_unused
: public std::false_type
{};
template<typename T, typename U>
struct is_elem_and_unused<
T,
U,
typename std::enable_if<
!sprout::weed::traits::is_unused<T>::value
&& sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP

View file

@ -0,0 +1,34 @@
#ifndef SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP
#define SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_same_container
: public std::false_type
{};
template<typename T, typename U>
struct is_same_container<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_container<T>::value
&& sprout::weed::traits::is_container<U>::value
&& std::is_same<
typename T::value_type,
typename U::value_type
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_tuple_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_same_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_same_elem<
T,
U,
typename std::enable_if<
std::is_same<T, U>::value
&& !is_same_container<T, U>::value
&& !is_container_and_elem<T, U>::value
&& !is_elem_and_container<T, U>::value
&& !is_both_tuple<T, U>::value
&& !is_tuple_and_elem<T, U>::value
&& !is_elem_and_tuple<T, U>::value
&& !sprout::weed::traits::is_unused<T>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_tuple.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_tuple_and_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_tuple_and_elem<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_tuple<T>::value
&& !sprout::weed::traits::is_tuple<U>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_unused_and_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_unused_and_elem<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_unused<T>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_WEED_DETAIL_UNCVREF_HPP
#define SPROUT_WEED_DETAIL_UNCVREF_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T>
struct uncvref
: public std::conditional<
std::is_array<T>::value
|| std::is_array<typename std::remove_reference<T>::type>::value,
typename std::remove_reference<T>::type,
typename std::decay<T>::type
>
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_UNCVREF_HPP

View file

@ -0,0 +1,86 @@
#ifndef SPROUT_WEED_DETAIL_XDIGITS_HPP
#define SPROUT_WEED_DETAIL_XDIGITS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/array.hpp>
#include <sprout/tuple/tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename Elem>
struct xdigits;
template<>
struct xdigits<char> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char, 22> table = sprout::to_string("0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<char, 22> sprout::weed::detail::xdigits<char>::table;
template<>
struct xdigits<wchar_t> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<wchar_t, 22> table = sprout::to_string(L"0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<wchar_t, 22> sprout::weed::detail::xdigits<wchar_t>::table;
template<>
struct xdigits<char16_t> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char16_t, 22> table = sprout::to_string(u"0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<char16_t, 22> sprout::weed::detail::xdigits<char16_t>::table;
template<>
struct xdigits<char32_t> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char32_t, 22> table = sprout::to_string(U"0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<char32_t, 22> sprout::weed::detail::xdigits<char32_t>::table;
template<typename Dummy>
struct xvalues;
template<>
struct xvalues<void> {
public:
SPROUT_STATIC_CONSTEXPR sprout::array<std::uint8_t, 22> table = sprout::array<std::uint8_t, 22>{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}
};
};
SPROUT_CONSTEXPR sprout::array<std::uint8_t, 22> sprout::weed::detail::xvalues<void>::table;
template<typename IntType>
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> xvalue_at(std::size_t i) {
return i < 22
? sprout::tuples::tuple<IntType, bool>(
static_cast<IntType>(sprout::weed::detail::xvalues<void>::table[i]),
true
)
: sprout::tuples::tuple<IntType, bool>(
IntType(),
false
)
;
}
template<typename IntType, typename Elem>
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_xdigit(Elem c) {
return sprout::weed::detail::xvalue_at<IntType>(
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(
sprout::weed::detail::xdigits<Elem>::table.begin(),
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::find(
sprout::weed::detail::xdigits<Elem>::table.begin(),
sprout::weed::detail::xdigits<Elem>::table.end(),
c
)
)
);
}
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_XDIGITS_HPP