Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Implementing Concepts
Description: Writing and using concept check tests.Keywords: ecl concepts
Tutorial Level: INTERMEDIATE
Overview
Usage is fairly simple. There are two steps:
Concept Test : must be hand crafted to check all the characteristic behaviours of a concept.
Concept Check : whenever required, call the concept check which runs the concept test to verify compliance.
Concept Test
If you are using an existing concept (see below), skip through to the concept check. Otherwise:
- Decide on a name for the concept.
- Create a templatised class of that name with a single arbitrary template argument (the class to be tested).
Hand craft the testing function within that class using compile_time_concept_test().
The example here is the same as that used in src/tests/concepts.cpp:
Hand-crafting the concept testing function will often require a little care to ensure the concept is appropriately covered.
Concept Check
Once you have a test in place, you only need to insert compile_time_concept_check() calls wherever you need them. Keep in mind, the sole purpose of these is to provide convenient error logs when something goes wrong.
1 class A { // This class has the MyConcept functionality.
2 public:
3 // The following function characterises the MyConcept concept.
4 // Comment this line and any MyConcept concept assertion
5 // check will fail in compile time.
6 void apply() {};
7 };
8
9 int main() {
10 compile_time_concept_check(MyConcept<A>); // Checks A for compliance to the MyConcept concept.
11 return 0;
12 }