|
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 14:27:24
Georgios Samaras wrote:
> I increased and it compile. However, I am -again- not able to
> continue, because now it says point not declared..
>
If you're talking about the point identifier used in the main() function
then yes, the compiler is right. The point type is declared inside
do_something() and is visible only inside this function. I understand
that template metaprogramming may be confusing but typedefs and
functions are elements of C language. I advice you to learn more about
C++ before proceeding. C++ Primer Plus by Stephen Prata is a nice book
but I'm sure you can find more in the Web.
This mailing list doesn't cover general C++, only Boost-related
questions should be posted here.
Regards,
Adam
> #include <boost/geometry.hpp>
> #include <boost/geometry/geometries/point.hpp>
> #include <boost/geometry/index/rtree.hpp>
>
> namespace bg = boost::geometry;
> namespace bgi = boost::geometry::index;
>
> template <int CompileTimeDimension>
> void do_something()
> {
> typedef bg::model::point<float, CompileTimeDimension,
> bg::cs::cartesian> point;
> bgi::rtree<point, bgi::linear<8> > rt;
> }
>
> template <std::size_t D, std::size_t N>
> struct fill
> {
> template <typename Point>
> static void apply(Point& p, typename
> bg::coordinate_type<Point>::type const& v)
> {
> bg::set<D>(p, v);
> fill<D + 1, N>::apply(p, v);
> }
> };
> template <std::size_t N>
> struct fill<N, N>
> {
> template <typename Point>
> static void apply(Point&, typename
> bg::coordinate_type<Point>::type const&) {}
> };
>
>
> int main()
> {
> int M;
> M = 100;
> if ( M == 100 )
> do_something<100>();
> else if ( M == 10000 )
> do_something<10000>();
> else
> std::cerr << "invalid dimension!";
> point p;
> if ( M == 100 )
> fill<0, 100>::apply(p, 5);
> else if ( M == 10000 )
> fill<0, 10000>::apply(p, 5);
> else
> std::cerr << "invalid dimension!";
> return 0;
> }
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