Re: how to boost::range_size work?
[restoring some context --ccox]
Thomas Maeder <maeder@glue.ch>:
template<typename T, std::size_t N>
std::vector<T> to_vector(T const (&i)[N])
{
return std::vector<T>(i,i+N);
}
chuchelo@gmail.com wrote:
there is too many constructors of std::vector
and in some cases it will generate vector of size 'i' with 'i+N'
element each :-(
How? (Except on a broken compiler)
'i' decays to a pointer in this context, and 'i+N' is a pointer of the
same type.
std::vector has the following constructors:
1) explicit vector(const Allocator& = Allocator());
2) explicit vector(size_type, const T& = T(), const Allocator& =
Allocator());
3) template <class InputIterator>
vector(InputIterator, InputIterator,
const Allocator& = Allocator());
4) vector(const vector<T,Allocator> &);
How could that possibly match any constructor other than #3?
There are two parameters, so that rules out #1 and #4, size_type is
never a pointer, so that rules out #2. #3 is the only thing left that a
compiler can choose.
--
Clark S. Cox III
clarkcox3@gmail.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]