(!) 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


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:

   1 template <typename T>
   2 class MyConcept {
   3     public:
   4         compile_time_concept_test(MyConcept) {
   5             T t;
   6             t.apply();  // This is the characteristic function required by this concept.
   7         }
   8 };

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 };
   9 int main() {
  10     compile_time_concept_check(MyConcept<A>); // Checks A for compliance to the MyConcept concept.
  11     return 0;
  12 }

Wiki: ecl_concepts/Tutorials/Implementing Concepts (last edited 2012-01-17 23:39:14 by DanielStonier)