variadic: use make_index_sequence from the stdlib

This commit is contained in:
Danny Robson 2017-06-07 16:31:55 +10:00
parent 2bc7e3e449
commit e019270a1f
4 changed files with 14 additions and 56 deletions

View File

@ -25,6 +25,7 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <utility>
#include <experimental/filesystem> #include <experimental/filesystem>
@ -360,11 +361,11 @@ namespace util {
template < template <
typename K, typename K,
typename I = typename make_indices< typename I = typename std::make_index_sequence<
std::tuple_size< std::tuple_size<
typename type<K>::fields typename type<K>::fields
>::value >::value
>::type >
> struct _type_tuple; > struct _type_tuple;
template < template <
@ -372,7 +373,7 @@ namespace util {
size_t ...I size_t ...I
> struct _type_tuple < > struct _type_tuple <
K, K,
indices<I...> std::index_sequence<I...>
> { > {
typedef std::tuple< typedef std::tuple<
typename std::tuple_element< typename std::tuple_element<
@ -394,11 +395,11 @@ namespace util {
namespace detail { namespace detail {
template < template <
typename K, typename K,
typename I = typename make_indices< typename I = typename std::make_index_sequence<
std::tuple_size< std::tuple_size<
typename type<K>::fields typename type<K>::fields
>::value >::value
>::type >
> >
struct _as_tuple; struct _as_tuple;
@ -408,7 +409,7 @@ namespace util {
> >
struct _as_tuple < struct _as_tuple <
K, K,
indices<I...> std::index_sequence<I...>
> >
{ {
static typename type_tuple<K>::type static typename type_tuple<K>::type

View File

@ -74,7 +74,7 @@ namespace util::tuple {
size_t ...I size_t ...I
> >
auto auto
call (const Func &func, std::tuple<Args...> args, indices<I...>) call (const Func &func, std::tuple<Args...> args, std::index_sequence<I...>)
{ {
// quiet unused variable warning with zero args // quiet unused variable warning with zero args
(void)args; (void)args;
@ -91,7 +91,7 @@ namespace util::tuple {
auto auto
call (const Func &func, std::tuple<Args...> args) call (const Func &func, std::tuple<Args...> args)
{ {
return detail::call (func, args, typename make_indices<sizeof...(Args)>::type {}); return detail::call (func, args, std::make_index_sequence<sizeof...(Args)> {});
} }
@ -137,9 +137,9 @@ namespace util::tuple {
template < template <
typename typename
> class F, > class F,
typename I = typename make_indices< typename I = std::make_index_sequence<
std::tuple_size<T>::value std::tuple_size<T>::value
>::type >
> >
struct map; struct map;
@ -155,7 +155,7 @@ namespace util::tuple {
struct map< struct map<
T, T,
F, F,
indices<I...> std::index_sequence<I...>
> { > {
typedef std::tuple< typedef std::tuple<
typename F< typename F<

View File

@ -11,29 +11,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* Copyright 2015 Danny Robson <danny@nerdcruft.net> * Copyright 2017 Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef __UTIL_VARIADIC_HPP #ifndef __UTIL_VARIADIC_HPP
#define __UTIL_VARIADIC_HPP #define __UTIL_VARIADIC_HPP
#include <cstddef> namespace util::variadic {
namespace util {
template <size_t ...N>
struct indices
{
typedef indices<N..., sizeof...(N)> next;
};
template <size_t N>
struct make_indices
{
typedef typename make_indices<N-1>::type::next type;
};
} }
#include "variadic.ipp"
#endif #endif

View File

@ -1,29 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
*/
#ifdef __UTIL_VARIADIC_IPP
#error
#endif
#define __UTIL_VARIADIC_IPP
namespace util {
template<>
struct make_indices<0>
{
typedef indices<> type;
};
}