2

I have such piece of code

    namespace bg = boost::geometry;
    typedef typename std::conditional<highDimension,
                                    typename bg::model::point<double, 6, bg::cs::cartesian>,
                                    typename bg::model::point<double, 5, bg::cs::cartesian>>::type point;
    ..........
    point p;                    
    p.set<0>(0);
    p.set<1>(0);
    p.set<2>(0);
    ..........

GCC show me a lot of errors like "error: invalid operands of types '' and 'int' to binary 'operator<' p.set<1>(col.a());" So it just try to 'compare' p.set and 1

The boost class really has template function set, but compiler don't use it as function.

If i make typedef directly from boost type, like typedef bg::model::point<double, 5, bg::cs::cartesian> point; everything works fine.

I just want to select different dimension sizes depending on template argument highDimension. But now I have no idea how to force GCC understand me :)

genpfault
  • 51,148
  • 11
  • 85
  • 139
johngull
  • 819
  • 6
  • 22

1 Answers1

5

Since highDimension is a template argument, point becomes a dependent type, so you need to write template here:

p.template set<0>(0);

As to why you need template there, read the answer here:


BTW, you don't need typename in the arguments:

typedef typename std::conditional<highDimension,
                 bg::model::point<double, 6, bg::cs::cartesian>,
                 bg::model::point<double, 5, bg::cs::cartesian>>::type point;

You could also use using:

using point = typename std::conditional<highDimension,
                 bg::model::point<double, 6, bg::cs::cartesian>,
                 bg::model::point<double, 5, bg::cs::cartesian>>::type;

This looks better from readability point of view (IMHO).

Or you could simply write this:

using point = bg::model::point<double, highDimension?6:5, bg::cs::cartesian>;

Looks even better.

Community
  • 1
  • 1
Nawaz
  • 353,942
  • 115
  • 666
  • 851