Skip to content

totally_ordered increases the size of the type (tested msvc2015) #8

Closed
@gaspardpetit

Description

I am a bit puzzled at the moment:

struct Foo1 : public tao::operators::less_than_comparable<Foo1>
{
	int i;
	bool operator==(const Foo1 &rhs) const { return i == rhs.i; }
	bool operator<(const Foo1 &rhs) const { return i < rhs.i; }
};

struct Foo2 : public tao::operators::equality_comparable<Foo2>
{
	int i;
	bool operator==(const Foo2 &rhs) const { return i == rhs.i; }
	bool operator<(const Foo2 &rhs) const { return i < rhs.i; }
};

struct Foo3 : public tao::operators::totally_ordered<Foo3>
{
	int i;
	bool operator==(const Foo3 &rhs) const { return i == rhs.i; }
	bool operator<(const Foo3 &rhs) const { return i < rhs.i; }
};
static_assert(sizeof(Foo1) == sizeof(int), "expected Foo1 to be the same size as a int");
static_assert(sizeof(Foo2) == sizeof(int), "expected Foo2 to be the same size as a int");
static_assert(sizeof(Foo3) == sizeof(int), "expected Foo3 to be the same size as a int");

Tested with msvc2015, this asserts on the third one:

error C2338: expected Foo3 to be the same size as a int

I don't think it is expected behaviour to increase the size of the implemented type and it seems related to the fact that totally_ordered has double inheritance.

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions