@lordpalandus: Neither
using nor
typedef require the pre-processor. I think you're thinking of
#define aliases.
@Arklon: I think I missed the point of the example here.
In particular, I don't see what is wrong with
BadIdea. I assume that is just a really simple allocator class. From what I see, it's never even going to have a chance to be used. The bad idea is simply the huge initial buffer size set by the
WhatCouldGoWrong alias. And also partly the misleading name
MySmallVector, since the library user is free to make that huge if they wanted to by setting a large initial size.
Hmm, also just noticed the
std::pair. I assume the
using clause is creating an alias for a 2D vector.
This is my understanding of the code:
class SimpleAllocator {
public:
void* Alloc(size_t size) { return alloca(size); }
void Free(const void*) { }
};
template <typename T, size_t InitialSize, typename Allocator>
class SmallSizeOptimizedVector {
...
std::aligned_storage_t<sizeof(T), alignof(T)> initialBuffer[InitialSize];
};
template <typename T>
using RidiculouslyHuge2DVector = SmallSizeOptimizedVector<std::pair<T, T>, 0xFFFFFFFFFFFFFFFF, SimpleAllocator>;
RidiculouslyHuge2DVector<float> vector2D; // { {x1, y1}, {x2, y2}, ... }
I'm guessing the example of the usefulness of
using was actually the 2D part, since that doubles up on the type. And also the ability to fill in the other details so you don't need to worry about them. Just that wasn't such a good thing in this example because it filled in bad details for one of those fields.