Sprout/sprout/string/tuple.hpp

55 lines
1.6 KiB
C++
Raw Normal View History

2012-04-14 10:06:21 +00:00
#ifndef SPROUT_STRING_TUPLE_HPP
#define SPROUT_STRING_TUPLE_HPP
#include <cstddef>
#include <tuple>
#include <type_traits>
#include <sprout/string/string.hpp>
2012-06-21 04:34:26 +00:00
#include <sprout/utility/move.hpp>
2012-09-29 09:41:13 +00:00
#include <sprout/tuple/tuple/get.hpp>
2012-06-21 04:34:26 +00:00
2012-09-29 09:41:13 +00:00
namespace sprout_adl {
//
// tuple_get
//
template<std::size_t I, typename T, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR T&
tuple_get(sprout::basic_string<T, N, Traits>& 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, typename Traits>
inline SPROUT_CONSTEXPR T const&
tuple_get(sprout::basic_string<T, N, Traits> 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, typename Traits>
inline SPROUT_CONSTEXPR T&&
tuple_get(sprout::basic_string<T, N, Traits>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace sprout_adl
2012-04-14 10:06:21 +00:00
namespace std {
//
// tuple_size
//
template<typename T, std::size_t N, typename Traits>
struct tuple_size<sprout::basic_string<T, N, Traits> >
2012-04-14 10:06:21 +00:00
: public std::integral_constant<std::size_t, N>
{};
//
// tuple_element
//
template<std::size_t I, typename T, std::size_t N, typename Traits>
struct tuple_element<I, sprout::basic_string<T, N, Traits> > {
2012-04-14 10:06:21 +00:00
public:
static_assert(I < N, "tuple_element<>: index out of range");
typedef T type;
};
} // namespace std
#endif // #ifndef SPROUT_STRING_TUPLE_HPP