Empty type in standard library

Sometimes it is necessary to pass an empty type to a template. For instance:

template <typename X, typename Y> struct BoundaryConditions { X x; Y y; BoundaryConditions(typename X::init xi, typename Y::init yi) : x(xi), y(yi) { ... } }; 

We may wish to implement free boundary conditions that do not accept any parameters. This is pretty easy to implement with type checking:

 struct Nothing {}; Nothing nothing = Nothing(); struct Free { typedef Nothing init; ... }; BoundaryConditions<Free, Fixed> foo(nothing, 100); 

So, the question of my question is: is there something like my type “Nothing” in the standard library or boost?

+6
source share
4 answers

You can use an empty tuple . Like std::tuple<>();

+6
source

What about boost::none and boost::none_t ?

http://www.boost.org/doc/libs/1_54_0/boost/none.hpp

+2
source

The usual solution is to use void , but this requires a partial specialization of the template (which is also usual, since otherwise it requires more space).

+2
source

Boost.MPL offers the void_ type.

0
source

Source: https://habr.com/ru/post/956233/


All Articles