From ecb46023f65964fc02c3eb97ee9821b55cc24c43 Mon Sep 17 00:00:00 2001 From: Sujin Philip Date: Thu, 21 Jun 2018 13:35:57 -0400 Subject: [PATCH] Add ListTagAppend and ListTagAppendUnique --- vtkm/ListTag.h | 16 ++++++++++++++++ vtkm/internal/ListTagDetail.h | 9 ++++++++- vtkm/testing/UnitTestListTag.cxx | 21 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/vtkm/ListTag.h b/vtkm/ListTag.h index 46ef653a0..b78691280 100644 --- a/vtkm/ListTag.h +++ b/vtkm/ListTag.h @@ -73,6 +73,22 @@ struct ListTagJoin : detail::ListRoot using list = typename detail::ListJoin::type; }; + +/// A tag that is constructed by appending \c Type to \c ListTag. +template +struct ListTagAppend : detail::ListRoot +{ + using list = typename detail::ListJoin>::type; +}; + +/// Append \c Type to \c ListTag only if \c ListTag does not already contain \c Type. +/// No checks are performed to see if \c ListTag itself has only unqiue elements. +template +struct ListTagAppendUnique : detail::ListRoot +{ + using list = typename detail::ListAppendUniqueImpl::type; +}; + /// A tag that consists of elements that are found in both tags. This struct /// can be subclassed and still behave like a list tag. template diff --git a/vtkm/internal/ListTagDetail.h b/vtkm/internal/ListTagDetail.h index cae6b80f8..3cb66236d 100644 --- a/vtkm/internal/ListTagDetail.h +++ b/vtkm/internal/ListTagDetail.h @@ -229,7 +229,14 @@ struct ListCrossProductImpl brigand::lazy::push_front>>>>>>>>>; }; - +//----------------------------------------------------------------------------- +template +struct ListAppendUniqueImpl +{ + using type = typename std::conditional::value, + List, + typename ListJoin>::type>::type; +}; } // namespace detail diff --git a/vtkm/testing/UnitTestListTag.cxx b/vtkm/testing/UnitTestListTag.cxx index 284619d17..29185902a 100644 --- a/vtkm/testing/UnitTestListTag.cxx +++ b/vtkm/testing/UnitTestListTag.cxx @@ -67,6 +67,18 @@ struct TestListTagUniversal : vtkm::ListTagUniversal { }; +struct TestListTagAppend : vtkm::ListTagAppend> +{ +}; + +struct TestListTagAppendUnique1 : vtkm::ListTagAppendUnique> +{ +}; + +struct TestListTagAppendUnique2 : vtkm::ListTagAppendUnique> +{ +}; + template std::pair test_number(brigand::list, TestClass>) { @@ -239,6 +251,15 @@ void TestLists() TryList(vtkm::Vec, 3>({ 31, 11 }, { 32, 11 }, { 33, 11 }), TestListTagCrossProduct()); + std::cout << "ListTagAppend" << std::endl; + TryList(vtkm::Vec(31, 32, 33, 34), TestListTagAppend()); + + std::cout << "ListTagAppendUnique1" << std::endl; + TryList(vtkm::Vec(31, 32, 33), TestListTagAppendUnique1()); + + std::cout << "ListTagAppendUnique2" << std::endl; + TryList(vtkm::Vec(31, 32, 33, 34), TestListTagAppendUnique2()); + std::cout << "ListTagUniversal" << std::endl;