mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
tuple/* 更新
This commit is contained in:
parent
9fd22666d3
commit
a7b415f2b1
7 changed files with 202 additions and 81 deletions
15
sprout/functional/hash/uuid.hpp
Normal file
15
sprout/functional/hash/uuid.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_UUID_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_UUID_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/uuid/uuid.hpp>
|
||||
|
||||
namespace sprout {
|
||||
SPROUT_CONSTEXPR std::size_t hash_value(sprout::uuids::uuid const& v) {
|
||||
return sprout::hash_range(v.begin(), v.end());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_UUID_HPP
|
32
sprout/tuple/array.hpp
Normal file
32
sprout/tuple/array.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef SPROUT_TUPLE_ARRAY_HPP
|
||||
#define SPROUT_TUPLE_ARRAY_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// get
|
||||
//
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
T& get(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
SPROUT_CONSTEXPR T const& get(sprout::array<T, N> const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
T&& get(sprout::array<T, N>&& t) SPROUT_NOEXCEPT {
|
||||
return std::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
} // namespace tuples
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_TUPLE_COMPARISON_HPP
|
32
sprout/tuple/sscrisk/cel/array.hpp
Normal file
32
sprout/tuple/sscrisk/cel/array.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP
|
||||
#define SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sscrisk/cel/array.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// get
|
||||
//
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
T& get(sscrisk::cel::array<T, N>& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
SPROUT_CONSTEXPR T const& get(sscrisk::cel::array<T, N> const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
T&& get(sscrisk::cel::array<T, N>&& t) SPROUT_NOEXCEPT {
|
||||
return std::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
} // namespace tuples
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP
|
32
sprout/tuple/string.hpp
Normal file
32
sprout/tuple/string.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef SPROUT_TUPLE_STRING_HPP
|
||||
#define SPROUT_TUPLE_STRING_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/string.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// get
|
||||
//
|
||||
template<std::size_t I, typename T, std::size_t N, typename Traits>
|
||||
T& get(sprout::basic_string<T, N, Traits>& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N, typename Traits>
|
||||
SPROUT_CONSTEXPR T const& get(sprout::basic_string<T, N, Traits> const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < N, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I, typename T, std::size_t N, typename Traits>
|
||||
T&& get(sprout::basic_string<T, N, Traits>&& t) SPROUT_NOEXCEPT {
|
||||
return std::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
} // namespace tuples
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_STRING_HPP
|
|
@ -261,48 +261,6 @@ namespace sprout {
|
|||
return sprout::tuples::tuple<Types&...>(args...);
|
||||
}
|
||||
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<typename T>
|
||||
struct tuple_size;
|
||||
template<typename T>
|
||||
struct tuple_size<T const>
|
||||
: public sprout::tuples::tuple_size<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct tuple_size<T volatile>
|
||||
: public sprout::tuples::tuple_size<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct tuple_size<T const volatile>
|
||||
: public sprout::tuples::tuple_size<T>
|
||||
{};
|
||||
template<typename... Types>
|
||||
struct tuple_size<sprout::tuples::tuple<Types...> >
|
||||
: public std::integral_constant<std::size_t, sizeof...(Types)>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element;
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element<I, T const> {
|
||||
public:
|
||||
typedef typename std::add_const<typename sprout::tuples::tuple_element<I, T>::type>::type type;
|
||||
};
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element<I, T volatile> {
|
||||
public:
|
||||
typedef typename std::add_volatile<typename sprout::tuples::tuple_element<I, T>::type>::type type;
|
||||
};
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element<I, T const volatile> {
|
||||
public:
|
||||
typedef typename std::add_cv<typename sprout::tuples::tuple_element<I, T>::type>::type type;
|
||||
};
|
||||
namespace detail {
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element_impl;
|
||||
|
@ -313,14 +271,64 @@ namespace sprout {
|
|||
};
|
||||
template<std::size_t I, typename Head, typename... Tail>
|
||||
struct tuple_element_impl<I, sprout::tuples::tuple<Head, Tail...> >
|
||||
: public sprout::tuples::tuple_element<I - 1, sprout::tuples::tuple<Tail...> >
|
||||
: public sprout::tuples::detail::tuple_element_impl<I - 1, sprout::tuples::tuple<Tail...> >
|
||||
{};
|
||||
} // namespace detail
|
||||
template<std::size_t I, typename... Types>
|
||||
struct tuple_element<I, sprout::tuples::tuple<Types...> >
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::tuples::tuple<Types...> >
|
||||
} // namespace tuples
|
||||
|
||||
using sprout::tuples::tuple;
|
||||
using sprout::tuples::ignore;
|
||||
using sprout::tuples::make_tuple;
|
||||
using sprout::tuples::forward_as_tuple;
|
||||
using sprout::tuples::tie;
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<typename... Types>
|
||||
struct tuple_size<sprout::tuples::tuple<Types...> >
|
||||
: public std::integral_constant<std::size_t, sizeof...(Types)>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I, typename... Types>
|
||||
struct tuple_element<I, sprout::tuples::tuple<Types...> >
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::tuples::tuple<Types...> >
|
||||
{};
|
||||
} // namespace std
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<typename T>
|
||||
struct tuple_size
|
||||
: public std::tuple_size<T>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element
|
||||
: public std::tuple_element<I, T>
|
||||
{};
|
||||
|
||||
//
|
||||
// get
|
||||
//
|
||||
template<std::size_t I, typename T>
|
||||
SPROUT_CONSTEXPR auto get(
|
||||
T&& t
|
||||
) SPROUT_NOEXCEPT -> decltype(std::get<I>(sprout::forward<T>(t)))
|
||||
{
|
||||
return std::get<I>(sprout::forward<T>(t));
|
||||
}
|
||||
//
|
||||
// get
|
||||
//
|
||||
|
@ -342,23 +350,23 @@ namespace sprout {
|
|||
} // namespace detail
|
||||
template<std::size_t I, typename... Types>
|
||||
SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type& get(
|
||||
tuple<Types...>& t
|
||||
sprout::tuples::tuple<Types...>& t
|
||||
) SPROUT_NOEXCEPT
|
||||
{
|
||||
return sprout::tuples::detail::get_helper<I>(t);
|
||||
}
|
||||
template<std::size_t I, typename... Types>
|
||||
SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&& get(
|
||||
tuple<Types...>&& t
|
||||
sprout::tuples::tuple<Types...>&& t
|
||||
) SPROUT_NOEXCEPT
|
||||
{
|
||||
return sprout::forward<typename tuple_element<I, sprout::tuples::tuple<Types...> >::type&&>(
|
||||
return sprout::forward<typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&&>(
|
||||
sprout::tuples::get<I>(t)
|
||||
);
|
||||
}
|
||||
template<std::size_t I, typename... Types>
|
||||
SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type const& get(
|
||||
tuple<Types...> const& t
|
||||
sprout::tuples::tuple<Types...> const& t
|
||||
) SPROUT_NOEXCEPT
|
||||
{
|
||||
return sprout::tuples::detail::get_helper<I>(t);
|
||||
|
@ -373,33 +381,10 @@ namespace sprout {
|
|||
}
|
||||
} // namespace tuples
|
||||
|
||||
using sprout::tuples::tuple;
|
||||
using sprout::tuples::ignore;
|
||||
using sprout::tuples::make_tuple;
|
||||
using sprout::tuples::forward_as_tuple;
|
||||
using sprout::tuples::tie;
|
||||
using sprout::tuples::tuple_size;
|
||||
using sprout::tuples::tuple_element;
|
||||
using sprout::tuples::get;
|
||||
using sprout::tuples::swap;
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<typename... Types>
|
||||
struct tuple_size<sprout::tuples::tuple<Types...> >
|
||||
: public sprout::tuples::tuple_size<sprout::tuples::tuple<Types...> >
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I, typename... Types>
|
||||
struct tuple_element<I, sprout::tuples::tuple<Types...> >
|
||||
: public sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >
|
||||
{};
|
||||
} // namespace std
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_TUPLE_HPP
|
||||
|
|
32
sprout/tuple/uuid.hpp
Normal file
32
sprout/tuple/uuid.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef SPROUT_TUPLE_UUID_HPP
|
||||
#define SPROUT_TUPLE_UUID_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/uuid/uuid.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// get
|
||||
//
|
||||
template<std::size_t I>
|
||||
sprout::uuids::uuid::value_type& get(sprout::uuids::uuid& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 16, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I>
|
||||
SPROUT_CONSTEXPR sprout::uuids::uuid::value_type const& get(sprout::uuids::uuid const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 16, "get: index out of range");
|
||||
return t[I];
|
||||
}
|
||||
template<std::size_t I>
|
||||
sprout::uuids::uuid::value_type&& get(sprout::uuids::uuid&& t) SPROUT_NOEXCEPT {
|
||||
return std::move(std::get<I>(t));
|
||||
}
|
||||
} // namespace tuples
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_UUID_HPP
|
|
@ -2,13 +2,6 @@
|
|||
#define SPROUT_UUID_UUID_HASH_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/uuid/uuid.hpp>
|
||||
|
||||
namespace sprout {
|
||||
SPROUT_CONSTEXPR std::size_t hash_value(sprout::uuids::uuid const& v) {
|
||||
return sprout::hash_range(v.begin(), v.end());
|
||||
}
|
||||
} // namespace sprout
|
||||
#include <sprout/functional/hash/uuid.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UUID_UUID_HASH_HPP
|
||||
|
|
Loading…
Reference in a new issue