SFINAE on 'is_pod'

I am one day old on SFINAE thing.

I am trying to write a vector 'uvector' class which:
- Acts like std::vector on non-POD types
- On POD types doesn't initialize elements on creation (use malloc/free without c'tors/d'tors).

So, why the compiler errors? What is wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// alias of std::vector
template<class T>
using uvector = std::vector<
	typename std::enable_if<!std::is_pod<T>::value, T>::type,
	std::allocator<T>>;

// completely new class
template<class T>
struct uvector<typename std::enable_if<std::is_pod<T>::value, T>::type>
{
	typedef T value_type;
	typedef T* iterator;
	....................
protected:
	T *f = 0;	//!< Pointer to first element of vector.
	T *l = 0;	//!< Pointer to last element of vector.
	T *c = 0;	//!< Pointer to the end of allocated memory block of vector. 
Last edited on
First, you have a couple missing typenames (one for each dependent ::type).

Second, type alias won't work here, for several reasons, the most fundamental of which is that std::vector, like the rest of the standard library containers, cannot be specialized. If you want a custom container, make a custom container that holds a vector as a member where necessary.

Topic archived. No new replies allowed.