LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TupleLookupByTag.h File Reference

Utilities to address elements of a tuple-like class by tag. More...

#include "larcorealg/CoreUtils/MetaUtils.h"
#include <cstddef>
#include <tuple>
#include <type_traits>

Go to the source code of this file.

Classes

struct  util::details::count_type_in_list_impl< Target, T >
 
struct  util::details::type_is_in_impl< Target, T >
 
struct  util::details::has_duplicate_types_unwrapper< Tuple >
 
struct  util::details::TagExtractorImpl< Tagged, typename >
 
struct  util::count_type_in_tuple< Target, Tuple >
 Holds whether the Target type is element of the specified std::tuple. More...
 
struct  util::extract_to_tuple_type< SrcTuple, Extractor, TargetClass >
 Returns type TargetClass<U...> from a SrcTuple<T...>. More...
 
struct  util::index_of_extracted_type< Extractor, Target, Tuple >
 Returns the index of the element in Tuple with the specified type. More...
 
struct  util::has_extracted_type< Extractor, Target, Tuple >
 Trait holding whether an element in Tuple type contains Target. More...
 
struct  util::has_duplicate_extracted_types< Extractor, Tuple >
 Traits holding whether elements of Tuple have duplicate types. More...
 
struct  util::count_extracted_types< Extractor, Target, Tuple >
 Counts the elements of a tuple-like type containing a Target type. More...
 
struct  util::TaggedType< T, Tag >
 A type with a specified tag. More...
 
struct  util::add_tag< T, Tag >
 
struct  util::remove_tag< Tagged >
 Trait holding the type contained in a TaggedType (or the type itself). More...
 
struct  util::remove_tag< TaggedType< T, Tag > >
 
struct  util::TagN<... >
 Tag class parametrized by a sequence of numbers. More...
 
struct  util::TagExtractor< Tagged >
 Extracts the tag from a type. More...
 
struct  util::details::count_type_in_list_impl< Target, T >
 
struct  util::details::count_type_in_list_impl< Target, First, Others... >
 
struct  util::details::count_type_in_list_impl< Target, Target, Others... >
 
struct  util::details::type_is_in_impl< Target, T >
 
struct  util::details::type_is_in_impl< Target, First, Others... >
 
struct  util::details::type_is_in_impl< Target, Target, Others... >
 
struct  util::details::extract_to_tuple_type_impl< TargetClass, Extractor, Tuple, I, N, T >
 Implementation for extract_to_tuple_type. More...
 
struct  util::details::extract_to_tuple_type_impl< TargetClass, Extractor, Tuple, N, N, T... >
 End-of-recursion specialization: packs all types already extracted into the target type. More...
 
struct  util::details::extract_to_tuple_type_impl_simple< SrcTuple, Extractor, TargetClass, I >
 
struct  util::details::index_of_extracted_type_impl< Extractor, Target, I, Elem, Tuple >
 
struct  util::details::index_of_extracted_type_checked< Extractor, Target, N, I, Tuple >
 
struct  util::details::index_of_extracted_type_checked< Extractor, Target, N, N, Tuple >
 
struct  util::details::index_of_extracted_type_impl< Extractor, Target, I, Elem, Tuple >
 
struct  util::details::index_of_extracted_type_impl< Extractor, Target, I, Target, Tuple >
 
struct  util::details::index_of_extracted_type_checked_after< Extractor, Target, N, After, Tuple >
 
struct  util::details::index_of_extracted_type_checked_after< Extractor, Target, N, N, Tuple >
 
struct  util::details::index_of_type_base< Extractor, Target, Tuple >
 
struct  util::details::index_of_type_helper< Extractor, Target, Tuple >
 
struct  util::details::has_duplicate_types_impl< Tuple, T >
 
struct  util::details::has_duplicate_types_impl< Tuple, First, Others... >
 
struct  util::details::has_duplicate_types_unwrapper< std::tuple< T... > >
 
struct  util::details::count_tags_in_list< Extractor, Target, Tags >
 
struct  util::details::count_tags_in_tuple< Extractor, Target, TagTuple >
 
struct  util::details::count_tags_in_tuple< Extractor, Target, std::tuple< Tags... > >
 
struct  util::details::TagExtractorImpl< Tagged, typename >
 
struct  util::details::TagExtractorImpl< Tagged, std::enable_if_t< always_true_type< typename std::remove_reference_t< Tagged >::tag >::value > >
 
struct  util::count_type_in_tuple< Target, Tuple >
 Holds whether the Target type is element of the specified std::tuple. More...
 
struct  util::count_type_in_tuple< Target, std::tuple< T... > >
 
struct  util::extract_to_tuple_type< SrcTuple, Extractor, TargetClass >
 Returns type TargetClass<U...> from a SrcTuple<T...>. More...
 
struct  util::index_of_extracted_type< Extractor, Target, Tuple >
 Returns the index of the element in Tuple with the specified type. More...
 
struct  util::has_extracted_type< Extractor, Target, Tuple >
 Trait holding whether an element in Tuple type contains Target. More...
 
struct  util::count_extracted_types< Extractor, Target, Tuple >
 Counts the elements of a tuple-like type containing a Target type. More...
 

Namespaces

 util
 Namespace for general, non-LArSoft-specific utilities.
 
 util::details
 

Typedefs

template<typename SrcTuple , template< typename T, typename... > class Extractor, template< typename... > class TargetClass = std::tuple>
using util::extract_to_tuple_type_t = typename extract_to_tuple_type< SrcTuple, Extractor, TargetClass >::type
 Direct access to the type in extract_to_tuple_type. More...
 
template<typename Tuple , template< typename... > class TargetClass = std::tuple>
using util::to_tuple = extract_to_tuple_type< Tuple, self_type, TargetClass >
 
template<typename Tuple , template< typename... > class TargetClass = std::tuple>
using util::to_tuple_t = typename to_tuple< Tuple, TargetClass >::type
 Direct access to the type in to_tuple. More...
 
template<typename Target , typename Tuple >
using util::index_of_type = index_of_extracted_type< self_type, Target, Tuple >
 
template<template< typename T, typename... > class Extractor, typename Target , typename Tuple >
using util::type_with_extracted_type = std::tuple_element< index_of_extracted_type_v< Extractor, Target, Tuple >, Tuple >
 Returns the element type in Tuple with the specified type. More...
 
template<template< typename T, typename... > class Extractor, typename Target , typename Tuple >
using util::type_with_extracted_type_t = typename type_with_extracted_type< Extractor, Target, Tuple >::type
 Direct access to the value in type_with_extracted_type. More...
 
template<typename Target , typename Tuple >
using util::has_type = has_extracted_type< self_type, Target, Tuple >
 
template<typename Tuple >
using util::has_duplicate_types = has_duplicate_extracted_types< self_type, Tuple >
 
template<typename Target , typename Tuple >
using util::count_types = count_extracted_types< self_type, Target, Tuple >
 
template<typename T , typename Tag >
using util::add_tag_t = typename add_tag< T, Tag >::type
 
template<typename Tagged >
using util::remove_tag_t = typename remove_tag< Tagged >::type
 Direct access to the type contained in remove_tag. More...
 
template<typename Tagged >
using util::tag_of = TagExtractor< Tagged >
 Trait holding the tag of Tagged as type. More...
 
template<typename Tagged >
using util::tag_of_t = typename tag_of< Tagged >::type
 Direct access to the type in tag_of. More...
 
template<typename SrcTuple >
using util::extract_tags = extract_to_tuple_type< SrcTuple, TagExtractor >
 Returns a tuple with all the tags from SrcTuple. More...
 
template<typename SrcTuple >
using util::extract_tags_t = typename extract_tags< SrcTuple >::type
 Direct access to the type in extract_tags. More...
 
template<typename Tag , typename Tuple >
using util::index_of_tag = index_of_extracted_type< TagExtractor, Tag, Tuple >
 Trait holding the index of the element of Tuple with tag Tag. More...
 
template<typename Tag , typename Tuple >
using util::type_with_tag = type_with_extracted_type< TagExtractor, Tag, Tuple >
 Trait holding the type of the element of Tuple with tag Tag. More...
 
template<typename Tag , typename Tuple >
using util::type_with_tag_t = typename type_with_tag< Tag, Tuple >::type
 Direct access to the value in type_with_tag. More...
 
template<typename Tag , typename Tuple >
using util::has_tag = has_extracted_type< TagExtractor, Tag, Tuple >
 Trait informing if there are elements in Tuple with tag Tag. More...
 
template<typename Tag , typename Tuple >
using util::count_tags = count_extracted_types< TagExtractor, Tag, Tuple >
 Trait counting the elements in Tuple with tag Tag. More...
 
template<typename Tuple >
using util::has_duplicate_tags = has_duplicate_extracted_types< TagExtractor, Tuple >
 Trait reporting if multiple elements in Tuple have the same tag. More...
 

Functions

template<template< typename T, typename... > class Extractor, typename Target , typename Tuple >
auto util::getByExtractedType (Tuple const &data) -> decltype(auto)
 Returns the value of the element containing the specified type. More...
 
template<typename Tag , typename T >
auto util::makeTagged (T &obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tag , typename T >
auto util::makeTagged (T const &obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tag , typename T >
auto util::makeTagged (T const &&obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tag , typename T >
auto util::makeTagged (T &&obj) -> decltype(auto)
 "Converts" obj to an object with tag Tag. More...
 
template<typename Tagged >
auto util::removeTag (Tagged &tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tagged >
auto util::removeTag (Tagged const &tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tagged >
auto util::removeTag (Tagged const &&tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tagged >
auto util::removeTag (Tagged &&tagged) -> decltype(auto)
 "Converts" a tagged type back to its original type. More...
 
template<typename Tag , typename Tuple >
auto util::getByTag (Tuple const &data) -> decltype(auto)
 Returns the object with the specified tag. More...
 

Variables

template<template< typename T, typename... > class Extractor, typename Target , typename Tuple >
constexpr std::size_t util::index_of_extracted_type_v
 Direct access to the value in index_of_extracted_type. More...
 
template<typename Target , typename Tuple >
constexpr std::size_t util::index_of_type_v = index_of_type<Target, Tuple>()
 Direct access to the value in index_of_type. More...
 
template<template< typename T, typename... > class Extractor, typename Target , typename Tuple >
constexpr bool util::has_extracted_type_v = has_extracted_type<Extractor, Target, Tuple>()
 Direct access to the value in has_extracted_type. More...
 
template<typename Target , typename Tuple >
constexpr bool util::has_type_v = has_type<Target, Tuple>()
 Direct access to the value in has_type. More...
 
template<template< typename T, typename... > class Extractor, typename Tuple >
constexpr bool util::has_duplicate_extracted_types_v
 Direct access to the value in has_duplicate_extracted_types. More...
 
template<typename Tuple >
constexpr bool util::has_duplicate_types_v = has_duplicate_types<Tuple>()
 Direct access to the value in has_duplicate_types. More...
 
template<template< typename T, typename... > class Extractor, typename Target , typename Tuple >
constexpr unsigned int util::count_extracted_types_v
 Direct access to the value in count_extracted_types. More...
 
template<typename Target , typename Tuple >
constexpr unsigned int util::count_types_v = count_types<Target, Tuple>()
 Direct access to the value in count_extracted_types. More...
 
template<typename Tag , typename Tuple >
constexpr std::size_t util::index_of_tag_v = index_of_tag<Tag, Tuple>()
 Direct access to the value in index_of_tag. More...
 
template<typename Tag , typename Tuple >
constexpr bool util::has_tag_v = has_tag<Tag, Tuple>()
 Direct access to the value in has_tag. More...
 
template<typename Tag , typename Tuple >
constexpr unsigned int util::count_tags_v = count_tags<Tag, Tuple>()
 Direct access to the value in count_tags. More...
 
template<typename Tuple >
constexpr bool util::has_duplicate_tags_v = has_duplicate_tags<Tuple>()
 Direct access to the value in has_duplicate_tags. More...
 
template<typename Target , typename... T>
using util::count_type_in_list = details::count_type_in_list_impl< Target, T... >
 Returns how many of the types in T exactly match Target. More...
 
template<std::size_t N, typename... T>
using util::typelist_element_type = std::tuple_element< N, std::tuple< T... >>
 Returns the N type of the type list. More...
 
template<std::size_t N, typename... T>
using util::typelist_element_t = typename typelist_element_type< N, T... >::type
 Direct access to the value in typelist_element_type. More...
 
template<typename Target , typename... T>
using util::type_is_in = details::type_is_in_impl< Target, T... >
 Holds whether the Target type is among the ones in the T pack. More...
 
template<typename Target , typename... T>
constexpr unsigned int util::count_type_in_list_v = count_type_in_list<Target, T...>()
 Direct access to the value in count_type_in_list. More...
 
template<typename Target , typename... T>
constexpr bool util::type_is_in_v = type_is_in<Target, T...>()
 Direct access to the value in type_is_in. More...
 

Detailed Description

Utilities to address elements of a tuple-like class by tag.

Author
Gianluca Petrillo
Date
August 17, 2018

A "tagged" class is a class containing a type named "tag". The class is tagged by it. A container of objects, tuple-like, can be accessed by specifying the type of the tag. For example:

std::tuple<TaggedItem1, TaggedItem2, TaggedItem3> data;
auto tagBdata = util::getByTag<TagB>(data);

will assign tagBdata with one of the three components of the data objects, the one whose type has tag equal to TagB.

The type being processed must be "tuple-like" (in the example above, the type of data is in fact a tuple). This means that the type must respond to std::tuple_element and std::tuple_size.

Beside these utilities, equivalent utilities are exposed that allow a different definition of the tag (via a class "returning" the tag of its only template argument), and that operate on the types directly rather than on the tags (equivalent to define the tag as the object itself).

All the type trait utilities follow the standard C++ convention: the ones "returning" a type have that type in a type member, and the ones returning a value have that value in a value member, and their instances can be implicitly converted to that value. Aliases ending with _t and _v are also provided.

This is a header-only library providing mostly type trait information.

Definition in file TupleLookupByTag.h.