Re: how to boost::range_size work?
chuchelo@gmail.com wrote:
I want to write code like this:
#include <vector>
#include <iostream>
#include <iterator>
template<std::size_t N>
std::vector<int> to_vector(const int i[N]){
std::vector<int> v;
v.assign(i,i+N);
return v;
};
int main(){
int V[5]={1,2,3,4,5};
std::vector<int> vec=to_vector(V);
Function templates parameterized with non-type parameters, such as
to_vector(), are rarely useful. After all, if the value of a parameter
is known at compile time, then why is a function needed? Furthermore, a
function template with a non-type parameter is prone to cause "code
bloat" by adding a signficant number of (nearly identical) routines to
a program that are not really needed.
Besides, the syntax for initializing a vector can more ecomonical
without using a special function:
int main()
{
const int N = 5;
int V[ N ] = { 1, 2, 3, 4, 5 };
std::vector<int> vec( V, V+N );
...
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]