#define as a workaround for missing concepts

Is this a good idea for a library developer to define a macro while we wait (hopefully) for inbound concepts ? What are the advantages and disadvantages of this approach?

Macro examples (A. Stepanova):

#define TotallyOrdered typename
#define Pointer typename
#define Number typename
#define Unsigned typename
#define Integral typename
#define InputIterator typename
#define OutputIterator typename
#define ForwardIterator typename
#define BidirectionalIterator typename
#define RandomAccessIterator typename
...

Usage example (from me):

template<ForwardIterator It>
It min_element(It first, It last) { ... }

Idea:

  • no concepts yet, this is a simple old code template
  • When the concepts finally arrive, you can delete all the macros or rename them if the names of the concepts are different (you can do this easily in any decent IDE), and then delete or simply override these macros in the concept expressions
  • Take advantage of future features without rewriting complex boilerplate code.
  • , "" .

< > : A. Amazon A9, , typename , , "- " ++, . , ( , , ). , . >

< > : GPU ( , , zipped iterators ..), , , >

+4
3

, .


, , , / .

, . , . , !


. , , -, . .

/ , .

+6

, . name , , , . , , all_of

template <class InputIterator, class Predicate>
bool all_of(InputIterator first, InputIterator last, Predicate pred);
+2

You can simply just have one macro, say CONCEPTS, and use it in your code as follows:

#ifdef CONCEPTS
// you concept based code
#else
// your temp workaround code
#endif

that way you can use a build tool (e.g. makefile) to control usage or lack of concepts.

0
source

Source: https://habr.com/ru/post/1622483/


All Articles