While testing out aggregate types I tried using boost::proto::is_aggregate in order to check if the types that I'm creating are truly aggregate. I wrote this code:
#include <iostream>
#include <boost\proto\traits.hpp>
struct IsAggregate
{
IsAggregate &operator=(IsAggregate const &rhs) {}
};
int main()
{
std::cout << std::boolalpha;
std::cout << boost::proto::is_aggregate<IsAggregate>() << std::endl;
return 0;
}
And I expected the output to be true since aggregate types can define a copy-assignment operator (according to this: What are Aggregates and PODs and how/why are they special?)
But the output is false.
I also used the aggregate classes inside of the previous answer which should have returned true but instead returned false.
This was tested on Boost 1.5.9 with both the Intel Compiler and MSVC.
Any ideas on why this has happened?
Proto's trait is clearly not intended for wider use.
It defaults to just call PODs aggregates and then simply lists 3 - library internal - types as aggregates explicitly. The behaviour described in the documentation indicates it was there to scratch an itch (the
make<>functions needed a way to know which types go withT{}and which go withT()).Taking a step back, you should probably reconsider your reasons for wanting this trait in the first place. You can most likely make your concept checks more specific.
Proposals to add a trait to the standard library have been met with broadly supported rejection:
I have looked at the requirements and have concluded it's hard/impossible to make a fool-proof implementation. The first requirement I was unable to address programmatically is
There's no way to tell a class has no (public, empty etc.) base class.
So the best thing I can come up is an approximation only:
Given the limitations, it seems to do its job fairly well, at least /a lot/ better than Proto's internal trait.
CAVEAT This doesn't address the subtle changes in c++11/c++14 (related to in-class member initializers e.g.). Also some of the traits used to compose the above approximation have known issues on various compiler versions (notably MSVC, as I remember), so do not trust this trait to be accurate across all language/library versions.
Live On Coliru
Coliru compiles this cleanly (without static asserts) on: