lundi 4 janvier 2016

Compile-time check if iterator's parent class public member exists

I have a class:

class A
{
// ...
public:
    std::string s;
// ...
}

And a function:

void some_process(RandomIt first, RandomIt last)
{
    static_assert(/* some check if *RandomIt has member with name `s` */,
                  "Iterator must point to an object with member `s`");

    // further process using RandomIt and using *RandomIt.s
}

How to implement this check in terms of C++ up to C++17?

Aucun commentaire:

Enregistrer un commentaire