Open erikzenker opened 7 years ago
As a first step I will describe the concepts as text comments and annotate the code with them e.g.:
// T models concept::Container
template<typename T>
void foo(T t)
{
}
Is there a nice way to define concepts if they are supported, but to ignore them if not? Without using preprocessor cheks?
Well, I don`t think so, because if they are not implemented by the compiler then a concept is an unknown keyword. But I think a simple macro is okay e.g.:
template<typename T>
GRAYBAT_ENABLE_CONCEPTS(requires SomeConcept<T>)
void foo(T t)
{
}
I think you could add preprocessor guards, that check for a specific compiler and therefore for concept support. But it's questionable if that is worth the hassle.
@fabian-jung: Of course. But nobody wants compiler check preprocessor magic in C++ Code in the year 2016. I guess the macro idea is better, which is basically the same, but only once and hidden. ;)
The CPP core guidelines have this to say: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rt-emulate
Well, yes you can use template metaprogramming to achieve something similar.
As I first step I collected concepts and started to describe them in a "concept like" way in #129.
Provide concept definitions for
CommunicationPolicy
,GraphPolicy
,Context
,Data
. Modern compilers such as gcc 6.x can process concept definitions with-fconcepts
.