Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a type similar to a struct with no members in the C++ standard library?

Tags:

c++

Sometimes it is necessary to pass a dummy value without any data to some template. For example:

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 doesn't take any parameters. It's pretty easy to implement such a thing with type checking:

struct Nothing {};
Nothing nothing = Nothing();

struct Free {
  typedef Nothing init;
  ...
};

BoundaryConditions<Free, Fixed> foo(nothing, 100);

So the matter of my question: is there an implementation of something like my Nothing type in the standard library or boost?

like image 764
user3974391 Avatar asked Oct 18 '13 11:10

user3974391


1 Answers

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

like image 127
Ivan Ishchenko Avatar answered Oct 27 '22 00:10

Ivan Ishchenko