1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

tuple/* 更新

This commit is contained in:
bolero-MURAKAMI 2011-10-31 17:31:03 +09:00
parent 9fd22666d3
commit a7b415f2b1
7 changed files with 202 additions and 81 deletions

View 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
View 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

View 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
View 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

View file

@ -261,48 +261,6 @@ namespace sprout {
return sprout::tuples::tuple<Types&...>(args...); 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 { namespace detail {
template<std::size_t I, typename T> template<std::size_t I, typename T>
struct tuple_element_impl; struct tuple_element_impl;
@ -313,14 +271,64 @@ namespace sprout {
}; };
template<std::size_t I, typename Head, typename... Tail> template<std::size_t I, typename Head, typename... Tail>
struct tuple_element_impl<I, sprout::tuples::tuple<Head, 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 } // namespace detail
} // 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> template<std::size_t I, typename... Types>
struct tuple_element<I, sprout::tuples::tuple<Types...> > struct tuple_element<I, sprout::tuples::tuple<Types...> >
: public sprout::tuples::detail::tuple_element_impl<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 // get
// //
@ -342,23 +350,23 @@ namespace sprout {
} // namespace detail } // namespace detail
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type& get( SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type& get(
tuple<Types...>& t sprout::tuples::tuple<Types...>& t
) SPROUT_NOEXCEPT ) SPROUT_NOEXCEPT
{ {
return sprout::tuples::detail::get_helper<I>(t); return sprout::tuples::detail::get_helper<I>(t);
} }
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&& get( SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&& get(
tuple<Types...>&& t sprout::tuples::tuple<Types...>&& t
) SPROUT_NOEXCEPT ) 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) sprout::tuples::get<I>(t)
); );
} }
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type const& get( 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 ) SPROUT_NOEXCEPT
{ {
return sprout::tuples::detail::get_helper<I>(t); return sprout::tuples::detail::get_helper<I>(t);
@ -373,33 +381,10 @@ namespace sprout {
} }
} // namespace tuples } // 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_size;
using sprout::tuples::tuple_element; using sprout::tuples::tuple_element;
using sprout::tuples::get; using sprout::tuples::get;
using sprout::tuples::swap; using sprout::tuples::swap;
} // namespace sprout } // 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 #endif // #ifndef SPROUT_TUPLE_TUPLE_HPP

32
sprout/tuple/uuid.hpp Normal file
View 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

View file

@ -2,13 +2,6 @@
#define SPROUT_UUID_UUID_HASH_HPP #define SPROUT_UUID_UUID_HASH_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp> #include <sprout/functional/hash/uuid.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_UUID_UUID_HASH_HPP #endif // #ifndef SPROUT_UUID_UUID_HASH_HPP