C++ Term Traits:

I would say traits are type properties

struct oracle;

struct postgres;

template<typename T>
void print_database(T t /* value only for type deduction -- avoiding explicit <>*/)
{
    /*Type resolution: database is unknown at this stage, database is a dependend type, but type dependend */

    if constexpr (is_same<typename T::database,oracle>::value) { cout << "oracle" << endl; return; }

    else if constexpr (is_same<typename T::database,postgres>::value) { cout << "postgres" << endl; return;}

    else { static_assert("Unsupported type"); }
}

struct abc
{
};

struct def
{
};

template<typename T>
struct db_traits;

template<>
struct db_traits<abc>
{
    using database = oracle;
};

template<>
struct db_traits<def>
{
    using database = postgres;
};

template<typename T>
struct something
{
    using database = typename T::database;
};

int main()
{
    something<abc> s;

    print_database(s);

    return 0;

}

Typetraits are lightweight information because the implementations of the types/structs/classes
are not of interest. Types are only names in this context.

Remark: Generic programming is like any abstraction if only one example is available. It makes things more complicated. But looking on universal properties it's clear it needs a bunch of examples to get a benefit. So many developers can live without it. But everyone
will try it - the "feature" effect.

C++ term concepts:

It's relatively new, available since C++-20. It an improvement in the area specification of templated constructions. Typically, in the C++ world it's forbidden to use a mathematical vocabulary. Make better specifications seems to be the goal. I have no personal experiences.

Remark2: C++ concepts is an additional feature but not a concept. The world of C++ scientists is restricted by C++. It's more a (distinct) feeling: replace concepts by ats-proofing.

Be sure, other c++ developers will tell you other things.

Am 03.07.20 um 20:10 schrieb gmhwxi:

Traits:

Based on my understanding, traits in C++ can be implemented in a more or less straightforward manner. To me, traits are an template-based approach for generating
ifdef-guards used in C.

However, I would prefer to take a deeper look at the template resolution algorithm. Traits are a bit like band-aid used at surface. One can expect to achieve a lot more if there is a logical way to affect the manner in which template code is replaced with non-template code.

Concepts:

It is a feature mainly for statically debugging templates. I am looking into it. Debugging templates statically is a big thing; I prefer something with clearer semantics. Let's wait and see.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/337ff3b2-40ed-43cc-9e0f-d62cfa6e4a42o%40googlegroups.com <https://groups.google.com/d/msgid/ats-lang-users/337ff3b2-40ed-43cc-9e0f-d62cfa6e4a42o%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/2fdd99da-d6e4-eb1c-8809-2fe2776ff913%40bejocama.de.

Reply via email to