 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Vaughn Cato Guest
|
Posted: Tue Jan 10, 2006 4:03 pm Post subject: n1919 |
|
|
I recently read Bjarne Stroustrup and Gabriel Dos Reis's paper on
generalized initializer lists. One point that I don't understand is
4.5.3. Here they say that having a T(&)[N] constructor wouldn't be
good because it would force all initializers to be templates, and that
treating the initializer as a constant would not be much of an
advantage. While I agree with these points, it seems there is an easy
solution.
template <typename T>
class initializer_list {
public:
template <size_t N>
initializer_list(const T (&init)[N])
: begin_(init),
end_(init+N)
{
}
private:
const T * begin_;
const T * end_;
};
Then you could have
template <typename T>
class Array {
public:
Array(const initializer_list<T> & init);
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|