[Documentation] [TitleIndex] [WordIndex

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

If you are using an existing concept (see below), skip through to the concept check. Otherwise:

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 }

2020-01-18 12:36