1 /* 2 Copyright (c) 2005-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef __TBB_test_common_initializer_list_support_H 18 #define __TBB_test_common_initializer_list_support_H 19 20 #include "config.h" 21 22 #include <initializer_list> 23 #include <vector> 24 25 namespace initializer_list_support_tests { 26 27 template <typename ContainerType, typename ElementType> 28 void test_ctor( std::initializer_list<ElementType> init, const ContainerType& expected ) { 29 ContainerType cont(init); 30 REQUIRE_MESSAGE(cont == expected, "Initialization via initializer_list failed"); 31 } 32 33 template <typename ContainerType, typename ElementType> 34 void test_assignment_operator( std::initializer_list<ElementType> init, const ContainerType& expected ) { 35 ContainerType cont; 36 cont = init; 37 REQUIRE_MESSAGE(cont == expected, "Assignment from the initializer_list failed"); 38 } 39 40 struct SkippedTest { 41 template <typename ContainerType, typename ElementType> 42 static void test( std::initializer_list<ElementType>, const ContainerType& ) {} 43 }; // struct SkippedTest 44 45 struct TestAssignMethod { 46 template <typename ContainerType, typename ElementType> 47 static void test( std::initializer_list<ElementType> init, const ContainerType& expected) { 48 ContainerType cont; 49 cont.assign(init); 50 REQUIRE_MESSAGE(cont == expected, "assign method with the initializer list argument failed"); 51 } 52 }; // struct TestAssign 53 54 struct TestInsertMethod { 55 template <typename ContainerType, typename ElementType> 56 static void test( std::initializer_list<ElementType> init, const ContainerType& expected) { 57 ContainerType cont; 58 cont.insert(init); 59 REQUIRE_MESSAGE(cont == expected, "insert method with the initializer list argument failed"); 60 } 61 }; // struct TestInsertMethod 62 63 template <typename ContainerType, typename TestAssign, typename TestSpecial> 64 void test_initializer_list_support( std::initializer_list<typename ContainerType::value_type> init ) { 65 using element_type = typename ContainerType::value_type; 66 std::vector<element_type> test_seq(init); 67 ContainerType expected(test_seq.begin(), test_seq.end()); 68 69 test_ctor(init, expected); 70 test_assignment_operator(init, expected); 71 TestAssign::test(init, expected); 72 TestSpecial::test(init, expected); 73 } 74 75 template <typename ContainerType, typename TestSpecial = SkippedTest> 76 void test_initializer_list_support( std::initializer_list<typename ContainerType::value_type> init ) { 77 test_initializer_list_support<ContainerType, TestAssignMethod, TestSpecial>(init); 78 } 79 80 template <typename ContainerType, typename TestSpecial = SkippedTest> 81 void test_initializer_list_support_without_assign( std::initializer_list<typename ContainerType::value_type> init ) { 82 test_initializer_list_support<ContainerType, SkippedTest, TestSpecial>(init); 83 } 84 85 } // namespace initializer_list_support_tests 86 87 #endif // __TBB_test_common_initializer_list_support_H 88