mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
add adapt std::array, std::pair
This commit is contained in:
parent
0437b24f12
commit
9e9556b62a
9 changed files with 218 additions and 2 deletions
10
sprout/adapt/std/array.hpp
Normal file
10
sprout/adapt/std/array.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef SPROUT_ADAPT_STD_ARRAY_HPP
|
||||||
|
#define SPROUT_ADAPT_STD_ARRAY_HPP
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/container/std/array.hpp>
|
||||||
|
#include <sprout/functional/hash/std/array.hpp>
|
||||||
|
#include <sprout/tuple/std/array.hpp>
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_ADAPT_STD_ARRAY_HPP
|
9
sprout/adapt/std/utility.hpp
Normal file
9
sprout/adapt/std/utility.hpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP
|
||||||
|
#define SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/functional/hash/std/utility.hpp>
|
||||||
|
#include <sprout/tuple/std/utility.hpp>
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP
|
59
sprout/container/std/array.hpp
Normal file
59
sprout/container/std/array.hpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#ifndef SPROUT_CONTAINER_STD_ARRAY_HPP
|
||||||
|
#define SPROUT_CONTAINER_STD_ARRAY_HPP
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||||
|
# include <cstddef>
|
||||||
|
# include <type_traits>
|
||||||
|
# include <sprout/container/traits.hpp>
|
||||||
|
# include <sprout/iterator/index_iterator.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// container_traits
|
||||||
|
//
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
struct container_traits<std::array<T, N> >
|
||||||
|
: public sprout::detail::container_traits_default<std::array<T, N> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef sprout::index_iterator<std::array<T, N>&, true> iterator;
|
||||||
|
typedef sprout::index_iterator<std::array<T, N> const&, true> const_iterator;
|
||||||
|
};
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// range_begin
|
||||||
|
//
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline typename sprout::container_traits<std::array<T, N> >::iterator
|
||||||
|
range_begin(std::array<T, N>& cont) {
|
||||||
|
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, 0);
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::const_iterator
|
||||||
|
range_begin(std::array<T, N> const& cont) {
|
||||||
|
return typename sprout::container_traits<std::array<T, N> >::const_iterator(cont, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// range_end
|
||||||
|
//
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline typename sprout::container_traits<std::array<T, N> >::iterator
|
||||||
|
range_end(std::array<T, N>& cont) {
|
||||||
|
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, cont.size());
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::const_iterator
|
||||||
|
range_end(std::array<T, N> const& cont) {
|
||||||
|
return typename sprout::container_traits<std::array<T, N> >::const_iterator(cont, cont.size());
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_CONTAINER_STD_ARRAY_HPP
|
|
@ -2,9 +2,9 @@
|
||||||
#define SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_ARRAY_HPP
|
#define SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_ARRAY_HPP
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <sscrisk/cel/array.hpp>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/functional/hash.hpp>
|
#include <sprout/functional/hash.hpp>
|
||||||
#include <sscrisk/cel/array.hpp>
|
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#define SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_UTILITY_HPP
|
#define SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_UTILITY_HPP
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <sscrisk/cel/utility.hpp>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/functional/hash.hpp>
|
#include <sprout/functional/hash.hpp>
|
||||||
#include <sscrisk/cel/utility.hpp>
|
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
|
|
20
sprout/functional/hash/std/array.hpp
Normal file
20
sprout/functional/hash/std/array.hpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef SPROUT_FUNCTIONAL_HASH_STD_ARRAY_HPP
|
||||||
|
#define SPROUT_FUNCTIONAL_HASH_STD_ARRAY_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <array>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/functional/hash.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// hash_value
|
||||||
|
//
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR std::size_t
|
||||||
|
hash_value(std::array<T, N> const& v) {
|
||||||
|
return sprout::hash_range(v);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_ARRAY_HPP
|
20
sprout/functional/hash/std/utility.hpp
Normal file
20
sprout/functional/hash/std/utility.hpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef SPROUT_FUNCTIONAL_HASH_STD_UTILITY_HPP
|
||||||
|
#define SPROUT_FUNCTIONAL_HASH_STD_UTILITY_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <utility>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/functional/hash.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// hash_value
|
||||||
|
//
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
inline SPROUT_CONSTEXPR std::size_t
|
||||||
|
hash_value(std::pair<T1, T2> const& v) {
|
||||||
|
return sprout::hash_values(v.first, v.second);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_UTILITY_HPP
|
34
sprout/tuple/std/array.hpp
Normal file
34
sprout/tuple/std/array.hpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef SPROUT_TUPLE_STD_ARRAY_HPP
|
||||||
|
#define SPROUT_TUPLE_STD_ARRAY_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <array>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/utility/move.hpp>
|
||||||
|
#include <sprout/tuple/tuple/get.hpp>
|
||||||
|
|
||||||
|
namespace sprout_adl {
|
||||||
|
//
|
||||||
|
// tuple_get
|
||||||
|
//
|
||||||
|
template<std::size_t I, typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR T&
|
||||||
|
tuple_get(std::array<T, N>& t) SPROUT_NOEXCEPT {
|
||||||
|
static_assert(I < N, "tuple_get: index out of range");
|
||||||
|
return t[I];
|
||||||
|
}
|
||||||
|
template<std::size_t I, typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR T const&
|
||||||
|
tuple_get(std::array<T, N> const& t) SPROUT_NOEXCEPT {
|
||||||
|
static_assert(I < N, "tuple_get: index out of range");
|
||||||
|
return t[I];
|
||||||
|
}
|
||||||
|
template<std::size_t I, typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR T&&
|
||||||
|
tuple_get(std::array<T, N>&& t) SPROUT_NOEXCEPT {
|
||||||
|
return sprout::move(sprout::tuples::get<I>(t));
|
||||||
|
}
|
||||||
|
} // namespace sprout_adl
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_TUPLE_STD_ARRAY_HPP
|
64
sprout/tuple/std/utility.hpp
Normal file
64
sprout/tuple/std/utility.hpp
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#ifndef SPROUT_TUPLE_STD_UTILITY_HPP
|
||||||
|
#define SPROUT_TUPLE_STD_UTILITY_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <array>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/utility/move.hpp>
|
||||||
|
#include <sprout/tuple/tuple.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
namespace tuples {
|
||||||
|
namespace detail {
|
||||||
|
template<std::size_t I, typename T>
|
||||||
|
struct get_impl;
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
struct get_impl<0, std::pair<T1, T2> > {
|
||||||
|
public:
|
||||||
|
SPROUT_CONSTEXPR T1& operator()(std::pair<T1, T2>& t) const {
|
||||||
|
return t.first;
|
||||||
|
}
|
||||||
|
SPROUT_CONSTEXPR T1 const& operator()(std::pair<T1, T2> const& t) const {
|
||||||
|
return t.first;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
struct get_impl<1, std::pair<T1, T2> > {
|
||||||
|
public:
|
||||||
|
public:
|
||||||
|
SPROUT_CONSTEXPR T2& operator()(std::pair<T1, T2>& t) const {
|
||||||
|
return t.second;
|
||||||
|
}
|
||||||
|
SPROUT_CONSTEXPR T2 const& operator()(std::pair<T1, T2> const& t) const {
|
||||||
|
return t.second;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace tuples
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
namespace sprout_adl {
|
||||||
|
//
|
||||||
|
// tuple_get
|
||||||
|
//
|
||||||
|
template<std::size_t I, typename T1, typename T2>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type&
|
||||||
|
tuple_get(std::pair<T1, T2>& t) SPROUT_NOEXCEPT {
|
||||||
|
static_assert(I < 2, "tuple_get: index out of range");
|
||||||
|
return sprout::tuples::detail::get_impl<I, std::pair<T1, T2> >()(t);
|
||||||
|
}
|
||||||
|
template<std::size_t I, typename T1, typename T2>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type const&
|
||||||
|
tuple_get(std::pair<T1, T2> const& t) SPROUT_NOEXCEPT {
|
||||||
|
static_assert(I < 2, "tuple_get: index out of range");
|
||||||
|
return sprout::tuples::detail::get_impl<I, std::pair<T1, T2> >()(t);
|
||||||
|
}
|
||||||
|
template<std::size_t I, typename T1, typename T2>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type&&
|
||||||
|
tuple_get(std::pair<T1, T2>&& t) SPROUT_NOEXCEPT {
|
||||||
|
return sprout::move(sprout::tuples::get<I>(t));
|
||||||
|
}
|
||||||
|
} // namespace sprout_adl
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_TUPLE_STD_UTILITY_HPP
|
Loading…
Reference in a new issue