vtk-m/vtkm/internal/Meta.h
Kenneth Moreland 2b64630674 Enable predicate parameter to ListAll and ListAny
In pretty much any practical circumstance, whenusing `ListAll` or
`ListAny`, you have a list of types on which you run some sort of
predicate on each item in the list to determine whether any or all of
the items match the predicate. To make this easier, add a second
argument to `ListAll` and `ListAny` to provide a predicate that will
automatically be added.

If no predicate is given, then the operation is run directly on the
list. This is implemented by just using an identity operation.
2022-03-08 09:26:35 -07:00

79 lines
2.3 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_internal_Meta_h
#define vtk_m_internal_Meta_h
// This header file contains templates that are helpful with template metaprogramming.
// Perhaps one day these structures can be exposed in the public interface, but the
// interface is a little wonky.
#include <type_traits>
namespace vtkm
{
namespace internal
{
namespace meta
{
/// A simple `struct` that holds a type without having to actually make the type object.
template <typename T>
struct Type
{
using type = T;
};
namespace detail
{
template <typename T1, typename T2>
struct AndImpl : std::integral_constant<bool, T1::value && T2::value>
{
};
template <typename T1, typename T2>
struct OrImpl : std::integral_constant<bool, T1::value || T2::value>
{
};
template <typename T>
struct NotImpl : std::integral_constant<bool, !T::value>
{
};
} // namespace detail
/// Expects two types, both with a `value` constant static value (like a `std::integral_constant`).
/// Resolves to a `std::integral_constant<bool, B>` where B is `T1::value && T2::value`.
template <typename T1, typename T2>
using And = typename detail::AndImpl<T1, T2>::type;
/// Expects two types, both with a `value` constant static value (like a `std::integral_constant`).
/// Resolves to a `std::integral_constant<bool, B>` where B is `T1::value || T2::value`.
template <typename T1, typename T2>
using Or = typename detail::OrImpl<T1, T2>::type;
/// Expects a type with a `value` constant static value (like a std::integral_constant`).
/// Resolves to a `std::integral_constant<bool, B>` where B is `!T::value`.
template <typename T>
using Not = typename detail::NotImpl<T>::type;
/// A single argument template that becomes its argument. Useful for passing an identity to
/// transformations.
template <typename T>
using Identity = T;
}
}
} // namespace vtkm::internal::meta
#endif //vtk_m_internal_Meta_h