Classes | Namespaces | Typedefs | Variables
type_list_utilities.hpp File Reference

Utilities for creating type lists for typed tests in Google Test. More...

#include "cudf_gtest.hpp"

Go to the source code of this file.

Classes

struct  cudf::test::AllSame
 Indicates if all types in a list are identical. More...
 
struct  cudf::test::ContainedIn< HAYSACK >
 Indicates if a type exists within a type list. More...
 
struct  cudf::test::Repeat< N >
 Transformation that repeats a type for a specified count. More...
 

Namespaces

 cudf
 cuDF interfaces
 

Typedefs

template<class TUPLE , int D>
using cudf::test::GetType = typename GetTypeImpl< TUPLE, D >::type
 Gives the specified type from a type list. More...
 
template<class... T>
using cudf::test::Concat = typename ConcatImpl< T... >::type
 Concatenates compile-time lists of types into a single type list. More...
 
template<class T >
using cudf::test::Flatten = typename FlattenImpl< T >::type
 Flattens nested compile-time lists of types into a single list of types. More...
 
template<class... ARGS>
using cudf::test::CrossProduct = typename CrossProductImpl< ARGS... >::type
 Creates a new type list from the cross product (cartesian product) of two type lists. More...
 
template<class PRED , class TUPLE >
using cudf::test::RemoveIf = typename RemoveIfImpl< PRED, TUPLE >::type
 Removes types from a type list that satisfy a predicate. More...
 
template<class XFORM , class TYPES >
using cudf::test::Transform = typename TransformImpl< XFORM, TYPES >::type
 Applies a transformation to every type in a type list. More...
 
template<class TYPES , class... ITEMS>
using cudf::test::Append = typename AppendImpl< TYPES, ITEMS... >::type
 Appends types to a type list. More...
 
template<class TUPLE , int... IDXs>
using cudf::test::Remove = typename RemoveImpl< TUPLE, IDXs... >::type
 Removes types at specified indices from a type list. More...
 
template<class TYPES >
using cudf::test::Unique = typename UniqueImpl< TYPES >::type
 Removes duplicate types from a type list. More...
 

Variables

template<class TUPLE >
constexpr auto cudf::test::GetSize = GetSizeImpl<TUPLE>::value
 Returns the size (number of elements) in a type list. More...
 
template<class NEEDLE , class HAYSACK >
constexpr bool cudf::test::Exists = ExistsImpl<NEEDLE, HAYSACK>::value
 Indicates if a type exists within a type list. More...
 

Detailed Description

Utilities for creating type lists for typed tests in Google Test.

A "type list" is a list of types passed to a Google Test type-parameterized test suite. The set of tests in the suite will be invoked once for each type in the list. Normally, this is done by using the testing::Types struct provided by GTest. For example,

using TestTypes = ::testing::Types<int, char, float>;
template <class T>
class TestFixture : ::testing::Test { };
TYPED_TEST_SUITE(TestFixture, TestTypes);
TYPED_TEST(TestFixture, mytest){
using Type0 = GetType<TypeParam,0>; // the first type element
}

The test mytest will be invoked 3 times, once for each of the types int, char, float.

Instead of using ::testing::Types directly, we provide cudf::test::Types. This is a drop in replacement for GTest's ::testing::Types. In lieu of including gtest/gtest.h, include cudf_gtest.hpp to ensure cudf::test::Types is used.

Using the utilities in this file, you can compose complex type lists.

For example, CrossProduct may be used to compute the cross-product of two or more type lists:

using TestTypes = CrossProduct<Types<int,float>,Types<char, void*>>;
// TestTypes == Types< <int,char> <int,void*> <float,char> <float,void*> >

RemoveIf can be used to remove some parameters that match a given predicate:

using TestTypes = RemoveIf<AllSame, CrossProduct<Types<int,char>,
*Types<int,char>>>;
// TestTypes == Types< <int,char>,<char,int> >
Note
WARNING: Abusing and overusing these utilities can lead to dramatically increased compile-times. Use responsibly.

Definition in file type_list_utilities.hpp.

Typedef Documentation

◆ Append

template<class TYPES , class... ITEMS>
using cudf::test::Append = typedef typename AppendImpl<TYPES, ITEMS...>::type

Appends types to a type list.

Example:

using MyTypes = Append<Types<int>, float, char>;
MyTypes == Types<int, float, char>;
Template Parameters
TYPESThe type list to append to
ITEMSThe types to append

Definition at line 539 of file type_list_utilities.hpp.

◆ Concat

template<class... T>
using cudf::test::Concat = typedef typename ConcatImpl<T...>::type

Concatenates compile-time lists of types into a single type list.

Example:

using MyTypes = Concat< Types<int, float>, Types<char, double>>
// MyTypes == Types<int, float, char, double>;

Definition at line 185 of file type_list_utilities.hpp.

◆ CrossProduct

template<class... ARGS>
using cudf::test::CrossProduct = typedef typename CrossProductImpl<ARGS...>::type

Creates a new type list from the cross product (cartesian product) of two type lists.

Note
This should be used with caution, as it can easily lead to a large number of typed test cases. For example, computing the CrossProduct of two type lists of size n and m, the resulting list will have n*m types.

Example:

using Types = CrossProduct<Types<int,float>, Types<char, double>>;
// Types == Types< Types<int, char>, Types<int, double>, Types<float, char>,
Types<float, double> >

Definition at line 288 of file type_list_utilities.hpp.

◆ Flatten

template<class T >
using cudf::test::Flatten = typedef typename FlattenImpl<T>::type

Flattens nested compile-time lists of types into a single list of types.

Example:

// Flatten< Types< int, Types< double, Types<char> > > == Types<int, double,
*char> static_assert(std::is_same<Flatten<Types<Types<int, Types<double>>,
*float>>, Types<int, double, float>>::value, "");

Definition at line 220 of file type_list_utilities.hpp.

◆ GetType

template<class TUPLE , int D>
using cudf::test::GetType = typedef typename GetTypeImpl<TUPLE, D>::type

Gives the specified type from a type list.

Example:

using T = GetType< Types<int, float, char, void*>, 2>
// T == char
Template Parameters
TUPLEThe type list
DIndex of the desired type

Definition at line 115 of file type_list_utilities.hpp.

◆ Remove

template<class TUPLE , int... IDXs>
using cudf::test::Remove = typedef typename RemoveImpl<TUPLE, IDXs...>::type

Removes types at specified indices from a type list.

Template Parameters
TUPLEType list to remove types from
IDXsIndices of types to remove

Definition at line 585 of file type_list_utilities.hpp.

◆ RemoveIf

template<class PRED , class TUPLE >
using cudf::test::RemoveIf = typedef typename RemoveIfImpl<PRED, TUPLE>::type

Removes types from a type list that satisfy a predicate.

Possible predicates: AllSame, ContainedIn

Example:

RemoveIf<AllSame, Types<Types<int, int, int>>> == Types<>
RemoveIf<AllSame, Types<Types<int, float, int>>> == Types<Types<int, float,
*int>>
using MyTypes = RemoveIf<ContainedIn<Types<Types<char, char>>>,
Types<Types<char, char>, Types<float,int>>>;
// MyTypes == Types<float, int>
Template Parameters
PREDThe predicate
TUPLEThe list of types on which to apply the predicate

Definition at line 441 of file type_list_utilities.hpp.

◆ Transform

template<class XFORM , class TYPES >
using cudf::test::Transform = typedef typename TransformImpl<XFORM, TYPES>::type

Applies a transformation to every type in a type list.

Possible transformations: Repeat

Example:

// Repeat transformation repeats each type for a specified count
using MyTypes = Transform<Repeat<2>, Types<int, float>>;
// MyTypes == Types< Types<int, int>, Types<float, float>>);
Template Parameters
XFORMThe transformation to apply
TYPESThe list of types to transform

Definition at line 470 of file type_list_utilities.hpp.

◆ Unique

template<class TYPES >
using cudf::test::Unique = typedef typename UniqueImpl<TYPES>::type

Removes duplicate types from a type list.

Example:

using MyTypes = Unique<Types<int, float, int, float>>;
MyTypes == Types<int, float>)
Template Parameters
TYPESThe type list from which to remove duplicates

Definition at line 626 of file type_list_utilities.hpp.

Variable Documentation

◆ Exists

template<class NEEDLE , class HAYSACK >
constexpr bool cudf::test::Exists = ExistsImpl<NEEDLE, HAYSACK>::value
constexpr

Indicates if a type exists within a type list.

Example:

// Exists<int, Types<float, double, int>> == true_type
// Exists<char, Types<int, float, void*>> == false_type
Template Parameters
NEEDLEThe type to search for
HAYSACKThe list to search in

Definition at line 369 of file type_list_utilities.hpp.

◆ GetSize

template<class TUPLE >
constexpr auto cudf::test::GetSize = GetSizeImpl<TUPLE>::value
constexpr

Returns the size (number of elements) in a type list.

Example:

GetSize< Types<int, float, double, void*> == 4

Definition at line 137 of file type_list_utilities.hpp.