tuple/type: commenting and style
This commit is contained in:
parent
f21369c15a
commit
2bbe6dc900
@ -6,46 +6,62 @@
|
|||||||
* Copyright 2015-2018 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2015-2018 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CRUFT_UTIL_TUPLE_TYPE_HPP
|
|
||||||
#define CRUFT_UTIL_TUPLE_TYPE_HPP
|
|
||||||
|
|
||||||
#include "../types.hpp"
|
#include "../types.hpp"
|
||||||
|
|
||||||
#include "../types/traits.hpp"
|
#include "../types/traits.hpp"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
|
||||||
namespace cruft::tuple::type {
|
namespace cruft::tuple::type {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
/// call a provided FunctorT with type_tag<T> for each type in the
|
/// Invoke a provided FunctorT with the provided arguments and a
|
||||||
/// tuple-like type TupleT.
|
/// type_tag<T> for each type in the tuple-like type TupleT.
|
||||||
|
///
|
||||||
|
/// The order of invocation is low-index to high-index (left to right).
|
||||||
|
///
|
||||||
|
/// \tparam TupleT A tuple-like type
|
||||||
|
/// \tparam FunctorT An invokable type
|
||||||
|
/// \tparam S The index to be invoked; this is private.
|
||||||
|
/// \tparam ArgsT User supplied arguments
|
||||||
template<
|
template<
|
||||||
typename TupleT,
|
typename TupleT,
|
||||||
typename FunctorT,
|
typename FunctorT,
|
||||||
size_t S = 0
|
size_t S = 0,
|
||||||
|
typename ...ArgsT
|
||||||
>
|
>
|
||||||
void
|
void
|
||||||
each (FunctorT &&func)
|
each (FunctorT &&func, ArgsT &&...args)
|
||||||
{
|
{
|
||||||
|
/// Get a handle on the type we need to forward.
|
||||||
static_assert (S < std::tuple_size_v<TupleT>);
|
static_assert (S < std::tuple_size_v<TupleT>);
|
||||||
using value_type = typename std::tuple_element<S,TupleT>::type;
|
using value_type = typename std::tuple_element<S,TupleT>::type;
|
||||||
|
|
||||||
func (cruft::type_tag<value_type> {});
|
/// Call the user's invokable.
|
||||||
|
std::invoke (func, args..., cruft::type_tag<value_type> {});
|
||||||
|
|
||||||
|
/// Recurse into ourselves with a higher index if we haven't reached
|
||||||
|
/// the end.
|
||||||
if constexpr (S + 1 < std::tuple_size_v<TupleT>) {
|
if constexpr (S + 1 < std::tuple_size_v<TupleT>) {
|
||||||
each<TupleT,FunctorT,S+1> (std::forward<FunctorT> (func));
|
each<TupleT,FunctorT,S+1> (
|
||||||
|
std::forward<FunctorT> (func),
|
||||||
|
std::forward<ArgsT> (args)...
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
/// Statically map the member types of a tuple via F<>::type
|
/// Convert a tuple-type holding an initial set of types into a tuple-type
|
||||||
|
/// holding a different set of types using the supplied transform:
|
||||||
|
/// `FieldT<...>`.
|
||||||
///
|
///
|
||||||
/// TupleT: tuple type
|
/// \tparam TupleT The initial tuple-type
|
||||||
/// FieldT: type mapping object, conversion uses FieldT<>::type
|
/// \tparam FieldT The type-transform type.
|
||||||
/// Indices: tuple indexing helper
|
/// The conversion uses FieldT<...>::type to perform the
|
||||||
|
/// conversions.
|
||||||
template <
|
template <
|
||||||
typename TupleT,
|
typename TupleT,
|
||||||
template <
|
template <
|
||||||
@ -80,11 +96,16 @@ namespace cruft::tuple::type {
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
/// query the index of the first occurrence of type `T' in the tuple-like
|
/// Query the index of the first occurrence of type `T' in the tuple-like
|
||||||
/// type `TupleT'.
|
/// type `TupleT'.
|
||||||
///
|
///
|
||||||
/// if the query type does not occur in the tuple type a compiler error
|
/// If the query type does not occur in the tuple type a compiler error
|
||||||
/// should be generated.
|
/// should be generated.
|
||||||
|
///
|
||||||
|
/// \tparam TupleT The tuple-type to be queried
|
||||||
|
/// \tparam ValueT The value-type we are searching for
|
||||||
|
///
|
||||||
|
/// The index will be defined as the size_t `::value` if it has been found.
|
||||||
template<
|
template<
|
||||||
typename TupleT,
|
typename TupleT,
|
||||||
typename ValueT,
|
typename ValueT,
|
||||||
@ -289,5 +310,3 @@ namespace cruft::tuple::type {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
using unique_t = typename unique<T>::type;
|
using unique_t = typename unique<T>::type;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user