constexpr Point reflection(const Point& p)noexcept{ Point res; res.setX(-p.xValue()); res.setY(-p.yValue()); return res; }
constexpr Point p1(9.4, 27.7); constexpr Point p2(28.8, 5.3); constexprauto mid = midpoint(p1, p2);
constexprauto reflectedMid = reflection(mid);
The Point constructor can be declared constexpr, because if the arguments passed to it are known during compilation, the value of the data members of the constructed Point can also be known during compilation. Points initialized could thus be constexpr. In C++14, even setters can be constexpr.
Conclusion:
constexpr objects are const and are initialized with values known during compilation.
constexpr functions can produce compile-time results when called with arguments whose values are known during compilation.
constexpr objects and functions may be used in a wider range of contexts than non-constexpr objects and functions.