Boost logo

Boost Users :

Subject: Re: [Boost-users] can not compile nearest neighbors in d dimensions
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-04-16 06:37:12


Hi Georgios,

Georgios Samaras wrote:
> >Long story short:
> >int const M = 3;
>
> I have checked the link already. Yes, I had tried that it worked, but,
> as I said the dimensions are going to be read from a file given by the
> user (that is run time I guess). That means that Boost can not let the
> user apply a desired dimension?
>
> If that is the case, how am I supposed to initialize the point? I have
> read the data in a 2D array and I do
>
> typedef bg::model::point<float, constM, bg::cs::cartesian> point;
> for(int j = 0 ; j < M ; ++j) {
> bg::set<j>(tmp, a[i][j]); // this
> will fail for the same reason you mentioned before, but it can not be
> const now
> //int const conj = j;
> //bg::set<(int const)j>(tmp, a[i][j]);
> }
>
> Sorry for asking again, but I can't make it work.

First, you should learn and understand the difference between run-time
function parameters and compile-time template parameters. There is a lot
of resources in the Web you can use.
In short, everything between <...> must be known at compile-time. In the
above code you try to use run-time variables (j) as template parameters.

To propose a solution we should know more about your application. The
user can define the dimension but may it be any number or are there some
bounds, i.e. min and max dimension?

Suppose the user may specify dimension 2 or 3, then you could use
something like this:

template <int CompileTimeDimension>
void do_something()
{
     typedef bg::model::point<float, CompileTimeDimension,
bg::cs::cartesian> point;

     // ...
}

// ...

if ( run_time_dimension == 2 )
     do_something<2>();
else if ( run_time_dimension == 3 )
     do_something<3>();
else
     std::cerr << "invalid dimension!";

Regards,
Adam


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net