how do you check if T is a certain type ?

how do i insert certain values if my type T is a certain type , ie i want to insert the value 1 into the vector_set if the type is int , and i want to insert the value 2 into the vector_set if the type is long ?




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

using def_con_test_types = boost::mpl::list<int, long, unsigned char, double, std::string, char>;
BOOST_AUTO_TEST_CASE_TEMPLATE(capacity2, T, def_con_test_types) {
	
	vector_set <T> v ;
	if (T == int)
	{
	   v.insert(1)
	}
	else if (T == long)
	{
		v.insert(2); 
	}
	
	//v.insert(1); 

	//cout << "capacity " << v.capacity() << endl;
	BOOST_TEST(v.capacity() >= v.size());
	BOOST_CHECK(v.capacity() >= v.size());

}
  
1
2
3
4
5
6
7
8
#include <type_traits>

template < typename T > void foo()
{
    // if T==int value = 1, else if T==long value = 2, else value = 3
    constexpr long long value = std::is_same<T,int>::value ? 1 :
                                    ( std::is_same<T,long>::value ? 2 : 3 ) ;
}
Last edited on
Last edited on
Topic archived. No new replies allowed.