C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

n1919

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Vaughn Cato
Guest





PostPosted: Tue Jan 10, 2006 4:03 pm    Post subject: n1919 Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.