Originally Posted by
Brafil
The things I would reconsider:
nullptr - It's not very elegant IMO. But I don't know a better way of doing it.
What do you think are the problems of nullptr? I've played around with it (and I've implemented it) and I find it very intuitive.
using instead of typedef. I didn't really grasp that.
Just a question: Isn't it possible to add template typedefs?
The alias declarations with 'using' can do that, yeah. You can actually have a lot of fun with them. The reason we have 'using' instead of 'typedef' is, I think, mainly one of grammar. The way typedef works, I think it would be very hard to make template typedefs that don't look absolutely atrocious. In general, the new syntax is much nicer than the arcane C syntax.
Code:
using INT = int;
// Arcane:
typedef void (*WhyIsTheNameHere)(int);
// Logical:
using ThisIsGood = void (*)(int);
// Template:
template <typename T>
using SpecialVector = std::vector<T, SpecialAllocator<T>>;
// Fun:
template <bool MutablePointer>
struct MetaFunction {
using type = std::string;
};
template <>
struct MetaFunction<true> {
using type = std::vector<char>;
};
template <bool MutablePointer>
using StringType = typename MetaFunction<MutablePointer>::type;
StringType<false> this_is_a_std_string;
Stringtype<true> this_is_a_char_vector;
Just another question: can you have mixed initalizer lists (std::initializer_list<int, char, double>)?
Initializer lists can be heterogenous, and the compiler will interpret the elements as constructor arguments and do overload resolution. However, std::initializer_list can only represent homogenous initializer lists.
Code:
class A {
A(int, float, std::string);
};
class B {
B(std::initializer_list<int>);
};
A a{1, 1, "hello"};
B b{1, 2, 3, 4, 5, 6, 7, 8, 9};