Commit 94bf457d authored by Sujin Philip's avatar Sujin Philip Committed by Kitware Robot

Merge topic 'add-ListTagAppend'

ecb46023 Add ListTagAppend and ListTagAppendUnique
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Robert Maynard's avatarRobert Maynard <robert.maynard@kitware.com>
Merge-request: !1278
parents e99aa10e ecb46023
......@@ -73,6 +73,22 @@ struct ListTagJoin : detail::ListRoot
using list = typename detail::ListJoin<typename ListTag1::list, typename ListTag2::list>::type;
};
/// A tag that is constructed by appending \c Type to \c ListTag.
template <typename ListTag, typename Type>
struct ListTagAppend : detail::ListRoot
{
using list = typename detail::ListJoin<typename ListTag::list, detail::ListBase<Type>>::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 <typename ListTag, typename Type>
struct ListTagAppendUnique : detail::ListRoot
{
using list = typename detail::ListAppendUniqueImpl<typename ListTag::list, Type>::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 <typename ListTag1, typename ListTag2>
......
......@@ -229,7 +229,14 @@ struct ListCrossProductImpl
brigand::lazy::push_front<brigand::_1, brigand::parent<brigand::_1>>>>>>>>>>;
};
//-----------------------------------------------------------------------------
template <typename List, typename Type>
struct ListAppendUniqueImpl
{
using type = typename std::conditional<ListContainsImpl<Type, List>::value,
List,
typename ListJoin<List, ListBase<Type>>::type>::type;
};
} // namespace detail
......
......@@ -67,6 +67,18 @@ struct TestListTagUniversal : vtkm::ListTagUniversal
{
};
struct TestListTagAppend : vtkm::ListTagAppend<TestListTag3, TestClass<34>>
{
};
struct TestListTagAppendUnique1 : vtkm::ListTagAppendUnique<TestListTag3, TestClass<32>>
{
};
struct TestListTagAppendUnique2 : vtkm::ListTagAppendUnique<TestListTagAppendUnique1, TestClass<34>>
{
};
template <int N, int M>
std::pair<int, int> test_number(brigand::list<TestClass<N>, TestClass<M>>)
{
......@@ -239,6 +251,15 @@ void TestLists()
TryList(vtkm::Vec<std::pair<int, int>, 3>({ 31, 11 }, { 32, 11 }, { 33, 11 }),
TestListTagCrossProduct());
std::cout << "ListTagAppend" << std::endl;
TryList(vtkm::Vec<int, 4>(31, 32, 33, 34), TestListTagAppend());
std::cout << "ListTagAppendUnique1" << std::endl;
TryList(vtkm::Vec<int, 3>(31, 32, 33), TestListTagAppendUnique1());
std::cout << "ListTagAppendUnique2" << std::endl;
TryList(vtkm::Vec<int, 4>(31, 32, 33, 34), TestListTagAppendUnique2());
std::cout << "ListTagUniversal" << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment