diff --git a/LICENSE.txt b/LICENSE.txt index 9750502b9..8842d2e63 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -76,3 +76,4 @@ CMake/FindTBB.cmake CMake/FindGLEW.cmake vtkm/cont/tbb/internal/parallel_sort.h vtkm/testing/OptionParser.h +vtkm/internal/brigand.hpp \ No newline at end of file diff --git a/vtkm/ListTag.h b/vtkm/ListTag.h index 71dd550b8..0c93099b5 100644 --- a/vtkm/ListTag.h +++ b/vtkm/ListTag.h @@ -32,7 +32,7 @@ namespace vtkm { namespace internal { template -struct ListTagCheck +struct ListTagCheck : std::is_base_of { static VTKM_CONSTEXPR bool Valid = std::is_base_of::value; @@ -47,57 +47,23 @@ struct ListTagCheck /// #define VTKM_IS_LIST_TAG(tag) \ VTKM_STATIC_ASSERT_MSG( \ - (::vtkm::internal::ListTagCheck::Valid), \ + (::vtkm::internal::ListTagCheck::value), \ "Provided type is not a valid VTK-m list tag.") -namespace detail { - -template -struct ListJoin { }; - -} // namespace detail /// A special tag for an empty list. /// struct ListTagEmpty : detail::ListRoot { - typedef detail::ListBase List; + using list = vtkm::detail::ListBase<>; }; /// A tag that is a construction of two other tags joined together. This struct /// can be subclassed and still behave like a list tag. template struct ListTagJoin : detail::ListRoot { - typedef detail::ListJoin List; + using list = typename detail::ListJoin::type; }; -template -VTKM_CONT_EXPORT -void ListForEach(Functor &f, ListTag); - -template -VTKM_CONT_EXPORT -void ListForEach(const Functor &f, ListTag); - -namespace detail { - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListJoin) -{ - vtkm::ListForEach(f, ListTag1()); - vtkm::ListForEach(f, ListTag2()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListJoin) -{ - vtkm::ListForEach(f, ListTag1()); - vtkm::ListForEach(f, ListTag2()); -} - -} // namespace detail - /// For each typename represented by the list tag, call the functor with a /// default instance of that type. /// @@ -106,7 +72,7 @@ VTKM_CONT_EXPORT void ListForEach(Functor &f, ListTag) { VTKM_IS_LIST_TAG(ListTag); - detail::ListForEachImpl(f, typename ListTag::List()); + detail::ListForEachImpl(f, typename ListTag::list()); } /// For each typename represented by the list tag, call the functor with a @@ -117,7 +83,7 @@ VTKM_CONT_EXPORT void ListForEach(const Functor &f, ListTag) { VTKM_IS_LIST_TAG(ListTag); - detail::ListForEachImpl(f, typename ListTag::List()); + detail::ListForEachImpl(f, typename ListTag::list()); } /// Checks to see if the given \c Type is in the list pointed to by \c ListTag. @@ -128,20 +94,10 @@ template struct ListContains { VTKM_IS_LIST_TAG(ListTag); - static const bool value = - detail::ListContainsImpl::value; + static VTKM_CONSTEXPR bool value = + detail::ListContainsImpl::value; }; -namespace detail { - -template -struct ListContainsImpl, Type> -{ - static const bool value = (vtkm::ListContains::value || - vtkm::ListContains::value); -}; - -} // namespace detail } // namespace vtkm diff --git a/vtkm/cont/CoordinateSystem.h b/vtkm/cont/CoordinateSystem.h index bf8d876d6..5a15db6ca 100644 --- a/vtkm/cont/CoordinateSystem.h +++ b/vtkm/cont/CoordinateSystem.h @@ -62,15 +62,15 @@ typedef vtkm::cont::ArrayHandleCompositeVectorType< /// by default (unless it is defined before including VTK-m headers. /// struct StorageListTagCoordinateSystemDefault - : vtkm::ListTagJoin< - VTKM_DEFAULT_STORAGE_LIST_TAG, - vtkm::ListTagBase, vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle >::StorageTag > > + vtkm::cont::ArrayHandle >::StorageTag > { }; typedef vtkm::cont::DynamicArrayHandleBase< diff --git a/vtkm/cont/DynamicArrayHandle.h b/vtkm/cont/DynamicArrayHandle.h index c240d7e91..0820e0f95 100644 --- a/vtkm/cont/DynamicArrayHandle.h +++ b/vtkm/cont/DynamicArrayHandle.h @@ -471,6 +471,7 @@ struct DynamicArrayHandleTryType { typedef DynamicArrayHandleTryStorage TryStorageType; TryStorageType tryStorage = TryStorageType(*this->Array, this->Function); + vtkm::ListForEach(tryStorage, StorageList()); if (tryStorage.FoundCast) { @@ -524,6 +525,7 @@ void DynamicArrayHandleBase::CastAndCall(const Functor &f) const { typedef detail::DynamicCellSetTryCellSet TryCellSetType; TryCellSetType tryCellSet = TryCellSetType(this->CellSetContainer.get(), f); + vtkm::ListForEach(tryCellSet, CellSetList()); if (!tryCellSet.FoundCast) { diff --git a/vtkm/internal/CMakeLists.txt b/vtkm/internal/CMakeLists.txt index 8034f7e6e..609aa9c11 100755 --- a/vtkm/internal/CMakeLists.txt +++ b/vtkm/internal/CMakeLists.txt @@ -58,6 +58,7 @@ set(headers FunctionInterfaceDetailPost.h FunctionInterfaceDetailPre.h IndexTag.h + IntegerSequence.h Invocation.h ListTagDetail.h ) @@ -66,7 +67,6 @@ vtkm_declare_headers(${headers}) vtkm_pyexpander_generated_file(FunctionInterfaceDetailPre.h) vtkm_pyexpander_generated_file(FunctionInterfaceDetailPost.h) -vtkm_pyexpander_generated_file(ListTagDetail.h) add_subdirectory(testing) diff --git a/vtkm/internal/FunctionInterface.h b/vtkm/internal/FunctionInterface.h index e9fc126fe..1f37e4614 100644 --- a/vtkm/internal/FunctionInterface.h +++ b/vtkm/internal/FunctionInterface.h @@ -23,27 +23,6 @@ #include #include - - -VTKM_THIRDPARTY_PRE_INCLUDE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -VTKM_THIRDPARTY_POST_INCLUDE - - - #include namespace vtkm { @@ -252,24 +231,23 @@ public: } - // the number of parameters as a boost mpl integral constant - typedef boost::function_types::function_arity SignatureArity; - - typedef typename boost::function_types::result_type::type - ResultType; - - typedef typename boost::function_types::components FunctionSignatureComponents; + // the number of parameters as an integral constant + typedef detail::FunctionSigInfo SigInfo; + typedef typename SigInfo::ArityType SignatureArity; + typedef typename SigInfo::ResultType ResultType; + typedef typename SigInfo::Components ComponentSig; + typedef typename SigInfo::Parameters ParameterSig; template struct ParameterType { - typedef typename detail::AtType::type type; + typedef typename detail::AtType::type type; }; static const bool RETURN_VALID = FunctionInterfaceReturnContainer::VALID; /// The number of parameters in this \c Function Interface. /// - static const vtkm::IdComponent ARITY = SignatureArity::value; + static const vtkm::IdComponent ARITY = SigInfo::Arity; /// Returns the number of parameters held in this \c FunctionInterface. The /// return value is the same as \c ARITY. @@ -481,17 +459,6 @@ public: detail::DoInvokeExec(f, this->Parameters, this->Result, transform); } - template - struct AppendType { - private: - typedef boost::mpl::single_view NewTypeSeq; - typedef boost::mpl::joint_view JointType; - typedef boost::function_types::function_type FuntionType; - public: - typedef FunctionInterface< typename FuntionType::type > type; - }; - - /// Returns a new \c FunctionInterface with all the parameters of this \c /// FunctionInterface and the given method argument appended to these /// parameters. The return type can be determined with the \c AppendType @@ -499,28 +466,17 @@ public: /// template VTKM_CONT_EXPORT - typename AppendType::type + FunctionInterface < typename detail::AppendType::type > Append(const NewType& newParameter) const { - typedef typename AppendType::type AppendInterfaceType; + typedef typename detail::AppendType::type AppendSignature; - AppendInterfaceType appendedFuncInterface; + FunctionInterface< AppendSignature > appendedFuncInterface; appendedFuncInterface.Copy(*this); appendedFuncInterface.template SetParameter(newParameter); return appendedFuncInterface; } - template - class ReplaceType { - typedef typename boost::mpl::advance_c::type, ParameterIndex>::type ToRemovePos; - typedef typename boost::mpl::erase::type ComponentRemoved; - typedef typename boost::mpl::advance_c::type, ParameterIndex>::type ToInsertPos; - typedef typename boost::mpl::insert::type ComponentInserted; - typedef typename boost::function_types::function_type::type NewSignature; - public: - typedef FunctionInterface type; - }; - /// Returns a new \c FunctionInterface with all the parameters of this \c /// FunctionInterface except that the parameter indexed at the template /// parameter \c ParameterIndex (also specified with the optional second @@ -560,13 +516,14 @@ public: /// template VTKM_CONT_EXPORT - typename ReplaceType::type + FunctionInterface < typename detail::ReplaceType::type > Replace(const NewType& newParameter, vtkm::internal::IndexTag = vtkm::internal::IndexTag()) const { - typename ReplaceType::type replacedFuncInterface; + typedef typename detail::ReplaceType::type ReplaceSigType; + FunctionInterface< ReplaceSigType > replacedFuncInterface; detail::FunctionInterfaceCopyParameters:: Copy(replacedFuncInterface.Parameters, this->Parameters); @@ -804,22 +761,20 @@ public: VTKM_CONT_EXPORT void operator()(const T& newParameter) const { - typedef typename FunctionInterface::FunctionSignatureComponents NewFSigComp; + typedef typename FunctionInterface::ComponentSig NewFSigComp; - typedef boost::mpl::single_view NewTypeSeq; - typedef boost::mpl::joint_view JointType; - typedef boost::function_types::function_type FuntionType; - typedef FunctionInterface< typename FuntionType::type > NextInterfaceType; + //Determine if we should do the next transform + using appended = brigand::push_back; + using interfaceSig = typename detail::AsSigType::type; + using NextInterfaceType = FunctionInterface< interfaceSig >; - //Determine if we should do the next transform, and if so convert from - //boost mpl to std::true_type/false_type ( for readability of sigs ) - typedef typename boost::mpl::less< - typename NextInterfaceType::SignatureArity, - typename vtkm::internal::FunctionInterface::SignatureArity - >::type IsLessType; - typedef std::integral_constant ShouldDoNextTransformType; + static VTKM_CONSTEXPR std::size_t newArity = NextInterfaceType::ARITY; + static VTKM_CONSTEXPR std::size_t oldArity = detail::FunctionSigInfo::Arity; + typedef std::integral_constant ShouldDoNextTransformType; NextInterfaceType nextInterface = this->NewInterface.Append(newParameter); + this->DoNextTransform(nextInterface, ShouldDoNextTransformType()); this->NewInterface.GetReturnValueSafe() = nextInterface.GetReturnValueSafe(); diff --git a/vtkm/internal/FunctionInterfaceDetailPre.h b/vtkm/internal/FunctionInterfaceDetailPre.h index c6d101b7f..682623467 100644 --- a/vtkm/internal/FunctionInterfaceDetailPre.h +++ b/vtkm/internal/FunctionInterfaceDetailPre.h @@ -30,10 +30,9 @@ #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -#include -VTKM_THIRDPARTY_POST_INCLUDE +#include + +#include #define VTKM_MAX_FUNCTION_PARAMETERS 10 @@ -48,13 +47,13 @@ namespace internal { template struct FunctionInterfaceReturnContainer { T Value; - static const bool VALID = true; + static VTKM_CONSTEXPR bool VALID = true; }; template<> struct FunctionInterfaceReturnContainer { // Nothing to store for void return. - static const bool VALID = false; + static VTKM_CONSTEXPR bool VALID = false; }; namespace detail { @@ -223,11 +222,51 @@ struct ParameterContainer { //============================================================================ -template< typename FS, int Index> -struct AtType +template struct FunctionSigInfo; +template +struct FunctionSigInfo { - typedef boost::function_types::components ParamterTypes; - typedef typename boost::mpl::at_c::type type; + static VTKM_CONSTEXPR std::size_t Arity = sizeof...(ArgTypes); + using ArityType = std::integral_constant; + + using ResultType = R; + using Components = brigand::list; + using Parameters = brigand::list; +}; + +template struct AtType; +template +struct AtType +{ + using type = brigand::at_c< brigand::list, Index>; +}; + +template struct AppendType; +template class L, typename T, typename NT, typename... U> +struct AppendType, NT> +{ + typedef T type(U...,NT); +}; + +template struct AsSigType; +template class L, typename T, typename... U> +struct AsSigType< L > +{ + typedef T type(U...); +}; + +template< typename Components, + vtkm::IdComponent ParameterIndex, + typename NewType > +class ReplaceType { + typedef std::integral_constant Index; + using split = brigand::split_at; + using front = brigand::push_back< brigand::front, NewType >; + using back = brigand::pop_front< brigand::back >; + + using replaced = brigand::append< front, back >; +public: + using type = typename AsSigType< replaced >::type; }; @@ -242,7 +281,7 @@ struct ParameterContainerAccess<1> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<1, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter1; } @@ -251,7 +290,7 @@ struct ParameterContainerAccess<1> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<1, FunctionSignature>::type &value) { parameters.Parameter1 = value; } }; @@ -262,7 +301,7 @@ struct ParameterContainerAccess<2> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<2, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter2; } @@ -271,7 +310,7 @@ struct ParameterContainerAccess<2> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<2, FunctionSignature>::type &value) { parameters.Parameter2 = value; } }; @@ -282,7 +321,7 @@ struct ParameterContainerAccess<3> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<3, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter3; } @@ -291,7 +330,7 @@ struct ParameterContainerAccess<3> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<3, FunctionSignature>::type &value) { parameters.Parameter3 = value; } }; @@ -302,7 +341,7 @@ struct ParameterContainerAccess<4> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<4, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter4; } @@ -311,7 +350,7 @@ struct ParameterContainerAccess<4> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<4, FunctionSignature>::type &value) { parameters.Parameter4 = value; } }; @@ -322,7 +361,7 @@ struct ParameterContainerAccess<5> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<5, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter5; } @@ -331,7 +370,7 @@ struct ParameterContainerAccess<5> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<5, FunctionSignature>::type &value) { parameters.Parameter5 = value; } }; @@ -342,7 +381,7 @@ struct ParameterContainerAccess<6> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<6, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter6; } @@ -351,7 +390,7 @@ struct ParameterContainerAccess<6> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<6, FunctionSignature>::type &value) { parameters.Parameter6 = value; } }; @@ -362,7 +401,7 @@ struct ParameterContainerAccess<7> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<7, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter7; } @@ -371,7 +410,7 @@ struct ParameterContainerAccess<7> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<7, FunctionSignature>::type &value) { parameters.Parameter7 = value; } }; @@ -382,7 +421,7 @@ struct ParameterContainerAccess<8> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<8, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter8; } @@ -391,7 +430,7 @@ struct ParameterContainerAccess<8> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<8, FunctionSignature>::type &value) { parameters.Parameter8 = value; } }; @@ -402,7 +441,7 @@ struct ParameterContainerAccess<9> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<9, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter9; } @@ -411,7 +450,7 @@ struct ParameterContainerAccess<9> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<9, FunctionSignature>::type &value) { parameters.Parameter9 = value; } }; @@ -422,7 +461,7 @@ struct ParameterContainerAccess<10> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<10, FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter10; } @@ -431,7 +470,7 @@ struct ParameterContainerAccess<10> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<10, FunctionSignature>::type &value) { parameters.Parameter10 = value; } }; diff --git a/vtkm/internal/FunctionInterfaceDetailPre.h.in b/vtkm/internal/FunctionInterfaceDetailPre.h.in index d84872120..3425bc799 100644 --- a/vtkm/internal/FunctionInterfaceDetailPre.h.in +++ b/vtkm/internal/FunctionInterfaceDetailPre.h.in @@ -42,10 +42,9 @@ $# Ignore the following comment. It is meant for the generated file. #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -#include -VTKM_THIRDPARTY_POST_INCLUDE +#include + +#include $py(max_parameters=10)\ #define VTKM_MAX_FUNCTION_PARAMETERS $(max_parameters) @@ -94,13 +93,13 @@ namespace internal { template struct FunctionInterfaceReturnContainer { T Value; - static const bool VALID = true; + static VTKM_CONSTEXPR bool VALID = true; }; template<> struct FunctionInterfaceReturnContainer { // Nothing to store for void return. - static const bool VALID = false; + static VTKM_CONSTEXPR bool VALID = false; }; namespace detail { @@ -124,11 +123,51 @@ $endfor\ $endfor\ //============================================================================ -template< typename FS, int Index> -struct AtType +template struct FunctionSigInfo; +template +struct FunctionSigInfo { - typedef boost::function_types::components ParamterTypes; - typedef typename boost::mpl::at_c::type type; + static VTKM_CONSTEXPR std::size_t Arity = sizeof...(ArgTypes); + using ArityType = std::integral_constant; + + using ResultType = R; + using Components = brigand::list; + using Parameters = brigand::list; +}; + +template struct AtType; +template +struct AtType +{ + using type = brigand::at_c< brigand::list, Index>; +}; + +template struct AppendType; +template class L, typename T, typename NT, typename... U> +struct AppendType, NT> +{ + typedef T type(U...,NT); +}; + +template struct AsSigType; +template class L, typename T, typename... U> +struct AsSigType< L > +{ + typedef T type(U...); +}; + +template< typename Components, + vtkm::IdComponent ParameterIndex, + typename NewType > +class ReplaceType { + typedef std::integral_constant Index; + using split = brigand::split_at; + using front = brigand::push_back< brigand::front, NewType >; + using back = brigand::pop_front< brigand::back >; + + using replaced = brigand::append< front, back >; +public: + using type = typename AsSigType< replaced >::type; }; @@ -144,7 +183,7 @@ struct ParameterContainerAccess<$(param_index)> { VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT_EXPORT - const typename AtType::type & + const typename AtType<$(param_index), FunctionSignature>::type & Get(const ParameterContainer ¶meters) { return parameters.Parameter$(param_index); } @@ -153,7 +192,7 @@ struct ParameterContainerAccess<$(param_index)> { template VTKM_EXEC_CONT_EXPORT void Set(ParameterContainer ¶meters, - const typename AtType::type &value) { + const typename AtType<$(param_index), FunctionSignature>::type &value) { parameters.Parameter$(param_index) = value; } }; diff --git a/vtkm/internal/IntegerSequence.h b/vtkm/internal/IntegerSequence.h new file mode 100644 index 000000000..29d960e92 --- /dev/null +++ b/vtkm/internal/IntegerSequence.h @@ -0,0 +1,81 @@ +//============================================================================ +// 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. +// +// Copyright 2014 Sandia Corporation. +// Copyright 2014 UT-Battelle, LLC. +// Copyright 2014 Los Alamos National Security. +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ + +#ifndef vtk_m_internal_IntegerSequence_h +#define vtk_m_internal_IntegerSequence_h + +#include + +namespace vtkm { +namespace internal { + +/// \brief A container of unsigned integers +/// +/// C++11 Doesn't provide an IntegerSequence class and helper constructor +// So we need to roll our own. This class has been tested up to 512 elements. +// +template struct IntegerSequence{}; + +namespace detail { + +template //unroll in blocks of 4 +struct MakeSeq : MakeSeq {}; + +template +struct MakeSeq<0,1,2,3,Is...> //termination case +{ using type = IntegerSequence<0,1,2,3,Is...>; }; + +template +struct PreMakeSeq : MakeSeq {}; + +template //specialization for value +1 to divisible by 4 +struct PreMakeSeq<1,N> : MakeSeq {}; + +template //specialization for value +2 to divisible by 4 +struct PreMakeSeq<2,N> : MakeSeq {}; + +template //specialization for value +3 to divisible by 4 +struct PreMakeSeq<3,N> : MakeSeq {}; + +template<> //specialization for 4 +struct PreMakeSeq<4,3> { using type = IntegerSequence<0,1,2,3>; }; + +template<> //specialization for 3 +struct PreMakeSeq<3,2> { using type = IntegerSequence<0,1,2>; }; + +template<> //specialization for 2 +struct PreMakeSeq<2,1> { using type = IntegerSequence<0,1>; }; + +template<> //specialization for 1 +struct PreMakeSeq<1,0> { using type = IntegerSequence<0>; }; + +template<> //specialization for 0 +struct PreMakeSeq<0,-1> { using type = IntegerSequence<>; }; + +} //namespace detail + +/// \brief A helper method to create an Integer sequence of 0...N-1. +template +struct MakeIntegerSequence : detail::PreMakeSeq {}; + +} +} + +#endif //vtk_m_internal_IntegerSequence_h diff --git a/vtkm/internal/ListTagDetail.h b/vtkm/internal/ListTagDetail.h index 008542cb3..d8a3e4cd9 100644 --- a/vtkm/internal/ListTagDetail.h +++ b/vtkm/internal/ListTagDetail.h @@ -17,8 +17,6 @@ // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ -// **** DO NOT EDIT THIS FILE!!! **** -// This file is automatically generated by FunctionInterfaceDetailPre.h.in #ifndef vtk_m_internal_ListTagDetail_h #define vtk_m_internal_ListTagDetail_h @@ -28,12 +26,9 @@ #endif #include - -#define VTKM_MAX_BASE_LIST 15 - +#include namespace vtkm { - namespace detail { //----------------------------------------------------------------------------- @@ -43,27 +38,143 @@ namespace detail { /// struct ListRoot { }; -template -struct ListBase { }; +template +using ListBase = brigand::list; //----------------------------------------------------------------------------- +template +struct ListJoin +{ + using type = brigand::append< typename ListTag1::list, typename ListTag2::list>; +}; + + +//----------------------------------------------------------------------------- +template struct ListContainsImpl; + +//----------------------------------------------------------------------------- +template +struct ListContainsImpl +{ + static VTKM_CONSTEXPR bool value = false; +}; + +//----------------------------------------------------------------------------- +template +struct ListContainsImpl > +{ + static VTKM_CONSTEXPR bool value = std::is_same< Type, T1 >::value; +}; + +//----------------------------------------------------------------------------- +template +struct ListContainsImpl > +{ + static VTKM_CONSTEXPR bool value = std::is_same< Type, T1 >::value || + std::is_same< Type, T2 >::value; +}; + +//----------------------------------------------------------------------------- +template +struct ListContainsImpl > +{ + static VTKM_CONSTEXPR bool value = std::is_same< Type, T1 >::value || + std::is_same< Type, T2 >::value || + std::is_same< Type, T3 >::value; +}; + +//----------------------------------------------------------------------------- +template +struct ListContainsImpl > +{ + static VTKM_CONSTEXPR bool value = std::is_same< Type, T1 >::value || + std::is_same< Type, T2 >::value || + std::is_same< Type, T3 >::value || + std::is_same< Type, T4 >::value; +}; + +//----------------------------------------------------------------------------- +template struct ListContainsImpl +{ + using find_result = brigand::find< List, + std::is_same< brigand::_1, Type> >; + using size = brigand::size; + static VTKM_CONSTEXPR bool value = (size::value != 0); +}; + +//----------------------------------------------------------------------------- +template +VTKM_CONT_EXPORT +void ListForEachImpl(const Functor &, brigand::empty_sequence) +{ +} + +template +VTKM_CONT_EXPORT +void ListForEachImpl(const Functor &f, brigand::list) +{ + f(T1()); +} + +template +VTKM_CONT_EXPORT +void ListForEachImpl(const Functor &f, brigand::list) +{ + f(T1()); + f(T2()); +} + +template +VTKM_CONT_EXPORT +void ListForEachImpl(const Functor &f, brigand::list) +{ + f(T1()); + f(T2()); + f(T3()); +} + +template +VTKM_CONT_EXPORT +void ListForEachImpl(const Functor &f, brigand::list) +{ + f(T1()); + f(T2()); + f(T3()); + f(T4()); + ListForEachImpl(f, brigand::list()); +} template VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &, ListBase) { } - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) +void ListForEachImpl(Functor &, brigand::empty_sequence) { - f(T1()); } template VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) +void ListForEachImpl(Functor &f, brigand::list) { f(T1()); } @@ -72,17 +183,7 @@ template VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) +void ListForEachImpl(Functor &f, brigand::list) { f(T1()); f(T2()); @@ -93,19 +194,7 @@ template VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) +void ListForEachImpl(Functor &f, brigand::list) { f(T1()); f(T2()); @@ -116,1248 +205,30 @@ template + typename T4, + typename... ArgTypes> VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) +void ListForEachImpl(Functor &f, brigand::list) { f(T1()); f(T2()); f(T3()); f(T4()); + ListForEachImpl(f, brigand::list()); } -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); - f(T13()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); - f(T13()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); - f(T13()); - f(T14()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); - f(T13()); - f(T14()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); - f(T13()); - f(T14()); - f(T15()); -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ - f(T1()); - f(T2()); - f(T3()); - f(T4()); - f(T5()); - f(T6()); - f(T7()); - f(T8()); - f(T9()); - f(T10()); - f(T11()); - f(T12()); - f(T13()); - f(T14()); - f(T15()); -} - - -//----------------------------------------------------------------------------- - -template -struct ListContainsImpl; - -template -struct ListContainsImpl, Type> -{ - static const bool value = false; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = false; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - } // namespace detail //----------------------------------------------------------------------------- /// A basic tag for a list of typenames. This struct can be subclassed /// and still behave like a list tag. -#if defined(VTKM_HAVE_CXX_11) template struct ListTagBase : detail::ListRoot { - typedef detail::ListBase List; -}; -#else -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; + using list = detail::ListBase; }; -template<> -struct ListTagBase<> : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -#endif - -} // namespace vtkm +} #endif //vtk_m_internal_ListTagDetail_h diff --git a/vtkm/internal/ListTagDetail.h.in b/vtkm/internal/ListTagDetail.h.in deleted file mode 100644 index d6b3ce6a0..000000000 --- a/vtkm/internal/ListTagDetail.h.in +++ /dev/null @@ -1,197 +0,0 @@ -//============================================================================ -// 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. -// -// Copyright 2014 Sandia Corporation. -// Copyright 2014 UT-Battelle, LLC. -// Copyright 2014 Los Alamos National Security. -// -// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, -// the U.S. Government retains certain rights in this software. -// -// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National -// Laboratory (LANL), the U.S. Government retains certain rights in -// this software. -//============================================================================ -$# This file uses the pyexpander macro processing utility to build the -$# FunctionInterface facilities that use a variable number of arguments. -$# Information, documentation, and downloads for pyexpander can be found at: -$# -$# http://pyexpander.sourceforge.net/ -$# -$# To build the source code, execute the following (after installing -$# pyexpander, of course): -$# -$# expander.py ListTagDetail.h.in > ListTagDetail.h -$# -$# Ignore the following comment. It is meant for the generated file. -// **** DO NOT EDIT THIS FILE!!! **** -// This file is automatically generated by FunctionInterfaceDetailPre.h.in - -#ifndef vtk_m_internal_ListTagDetail_h -#define vtk_m_internal_ListTagDetail_h - -#if !defined(vtk_m_ListTag_h) && !defined(VTKM_TEST_HEADER_BUILD) -#error ListTagDetail.h must be included from ListTag.h -#endif - -#include - -$py(max_base_list=15)\ -#define VTKM_MAX_BASE_LIST $(max_base_list) - -$# Python commands used in template expansion. -$py( -def comma_if(flag): - if flag: - return ',' - else: - return ''; - -def template_params(num_params, name='T', start=1, default=''): - if num_params < start: - return '' - result = 'typename %s%d%s' % (name, start, default) - for param in xrange(start+1, num_params+1): - result += ',\n typename %s%d%s' % (name, param, default) - return result - -def param_list(num_params, name='T', start=1): - if num_params < start: - return '' - result = '%s%d' % (name, start) - for param in xrange(start+1, num_params+1): - result += ',%s%d' % (name, param) - return result - -def signature(num_params, name='T', return_type='void', start=1): - result = '%s(' % return_type - if num_params >= start: - result += '%s%d' % (name, start) - for param in xrange(start+1, num_params+1): - result += ',%s%d' % (name, param) - result += ')' - return result -)\ -$# -$extend(comma_if, param_list, template_params, signature)\ - -namespace vtkm { - -namespace detail { - -//----------------------------------------------------------------------------- - -/// Base class that all ListTag classes inherit from. Helps identify lists -/// in macros like VTKM_IS_LIST_TAG. -/// -struct ListRoot { }; - -template -struct ListBase { }; - -//----------------------------------------------------------------------------- - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &, ListBase) { } - -$for(num_params in xrange(1, max_base_list+1))\ -template -VTKM_CONT_EXPORT -void ListForEachImpl(Functor &f, ListBase) -{ -$for(param_index in range(1, num_params+1))\ - f(T$(param_index)()); -$endfor\ -} - -template -VTKM_CONT_EXPORT -void ListForEachImpl(const Functor &f, ListBase) -{ -$for(param_index in range(1, num_params+1))\ - f(T$(param_index)()); -$endfor\ -} - -$endfor\ - -//----------------------------------------------------------------------------- - -template -struct ListContainsImpl; - -template -struct ListContainsImpl, Type> -{ - static const bool value = false; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = false; -}; - -$for(num_params in xrange(2, max_base_list+1))\ -template -struct ListContainsImpl, Type> -{ - static const bool value = true; -}; - -template -struct ListContainsImpl, Type> -{ - static const bool value = - ListContainsImpl, Type>::value; -}; - -$endfor\ - -} // namespace detail - -//----------------------------------------------------------------------------- -/// A basic tag for a list of typenames. This struct can be subclassed -/// and still behave like a list tag. -#if defined(VTKM_HAVE_CXX_11) -template -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; -#else -template<$template_params(max_base_list, default=' = vtkm::internal::NullType')> -struct ListTagBase : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -$for(num_params in xrange(0, (max_base_list+1)-1))\ -template<$template_params(num_params)> -struct ListTagBase<$param_list(num_params)> : detail::ListRoot -{ - typedef detail::ListBase List; -}; - -$endfor\ -#endif - -} // namespace vtkm - -#endif //vtk_m_internal_ListTagDetail_h diff --git a/vtkm/internal/brigand.hpp b/vtkm/internal/brigand.hpp new file mode 100644 index 000000000..d4d52a6fc --- /dev/null +++ b/vtkm/internal/brigand.hpp @@ -0,0 +1,2555 @@ +/*================================================================================================== + Copyright (c) 2015 Edouard Alligand and Joel Falcou + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +=================================================================================================**/ +#ifndef BRIGAND_HPP_INCLUDED +#define BRIGAND_HPP_INCLUDED + +#ifndef BRIGAND_NO_BOOST_SUPPORT +#define BRIGAND_NO_BOOST_SUPPORT +#endif + +#include +#include +namespace brigand +{ + template struct list {}; + template + using integral_list = brigand::list< std::integral_constant...>; + using empty_sequence = brigand::list<>; +} +namespace brigand +{ + namespace lazy + { + template class B> struct wrap; + template class A, class... T, template class B> + struct wrap, B> + { + using type = B; + }; + } + template class B> + using wrap = typename lazy::wrap::type; +} +namespace brigand +{ +namespace detail +{ + template + struct append_impl + { + using type = brigand::empty_sequence; + }; + template + struct append_impl + { + using type = T; + }; + template