Информация об изменениях

Сообщение Re[7]: char *(*(**foo[][8])())[]; - за сколько распарсите? от 20.04.2023 23:50

Изменено 21.04.2023 6:07 rg45

Re[7]: char *(*(**foo[][8])())[]; - за сколько распарсите?
Здравствуйте, kov_serg, Вы писали:

_>http://coliru.stacked-crooked.com/a/895450c6e1f7529f


BTW, ты напрасно начал прикручивать списки формальных параметров к специализации для членов классов. Эта специализация является общей для любых нестатических членов — членов-данных и членов-функций.

_>А лямбды можно впихать?


Можно, но только с ограничением: без auto в параметрах. Тип возвращаемого значения может быть auto.

http://coliru.stacked-crooked.com/a/dac5b55966f0dbbc

#include <iostream>
#include <string>

template <typename T, typename=void> struct TypeFormatter { std::string operator()() const { return "unknown type"; } };

template <typename...> struct FormatParamList;
template <> struct FormatParamList<> { std::string operator()() const {return {};} };
template <typename A, typename...X> struct FormatParamList<A, X...> { std::string operator()() const { return (TypeFormatter<A>{}() + ... + (", " + TypeFormatter<X>{}()));} };

template <typename> struct FunObjFormatter;
template <typename T, typename C, typename...A> struct FunObjFormatter<T(C::*)(A...)> { std::string operator()() const {return "functional object (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };
template <typename T, typename C, typename...A> struct FunObjFormatter<T(C::*)(A...) const> { std::string operator()() const {return "immutable functional object (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };

template <> struct TypeFormatter<void> { std::string operator()() const { return "void"; } };
template <> struct TypeFormatter<int> { std::string operator()() const { return "int"; } };
template <> struct TypeFormatter<char> { std::string operator()() const { return "char"; } };
template <> struct TypeFormatter<double> { std::string operator()() const { return "double"; } };
template <> struct TypeFormatter<std::string> { std::string operator()() const { return "std::string"; } };
template <typename T> struct TypeFormatter<const T> { std::string operator()() const { return "const " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T*> { std::string operator()() const { return "pointer to " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T&> { std::string operator()() const { return "lvalue refrence to " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T[]> { std::string operator()() const { return "array of unspecified size of " + TypeFormatter<T>()(); } };
template <typename T, size_t N> struct TypeFormatter<T[N]> { std::string operator()() const { return "array [" + std::to_string(N) + "] of " + TypeFormatter<T>()(); } };
template <typename T, typename C> struct TypeFormatter<T C::*> { std::string operator()() const {return "pointer to member of '" + TypeFormatter<C>()() + "' of type: " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T, std::void_t<typename T::TypeFormatter>> : T::TypeFormatter{};
template <typename T, typename...A> struct TypeFormatter<T(A...)> { std::string operator()() const {return "function (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };
template <typename T, typename...A> struct TypeFormatter<T(A...) const> { std::string operator()() const {return "immutable function (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };
template <typename T> struct TypeFormatter<T, std::void_t<decltype(&T::operator())>> : FunObjFormatter<decltype(&T::operator())> {};

namespace NS {
    struct A { };
};
//using NS::A;
//typedef NS::A A;
struct A:NS::A {};

template <> struct TypeFormatter<A> { std::string operator()() const {return "struct A";} };

int main()
{
    std::cout << TypeFormatter< char*(*(**[][8])())[] >()() << std::endl;
    std::cout << TypeFormatter< int (*)(char,char*(*(**[][8])())[],int) >()() << std::endl;
    std::cout << TypeFormatter< int (*)() >()() << std::endl;
    std::cout << TypeFormatter< int A::* >()() << std::endl;

    std::cout << TypeFormatter<int(const char&, double&)>()() << std::endl;
    std::cout << TypeFormatter<int(const char&, double&) const>()() << std::endl;
    std::cout << TypeFormatter<int()>()() << std::endl;
    std::cout << TypeFormatter<int() const>()() << std::endl;

    auto l1 = []{};
    auto l2 = [](int) { return 3.14; };
    auto l3 = [](int) mutable { return 3.14; };
    auto l4 = [](int, const std::string&, const char*, double) mutable { return 3.14; };

    std::cout << TypeFormatter<decltype(l1)>()() << std::endl;
    std::cout << TypeFormatter<decltype(l2)>()() << std::endl;
    std::cout << TypeFormatter<decltype(l3)>()() << std::endl;
    std::cout << TypeFormatter<decltype(l4)>()() << std::endl;
}

array of unspecified size of array [8] of pointer to pointer to function () returning pointer to array of unspecified size of pointer to char
pointer to function (char, pointer to array [8] of pointer to pointer to function () returning pointer to array of unspecified size of pointer to char, int) returning int
pointer to function () returning int
pointer to member of 'struct A' of type: int
function (lvalue refrence to const char, lvalue refrence to double) returning int
immutable function (lvalue refrence to const char, lvalue refrence to double) returning int
function () returning int
immutable function () returning int
immutable functional object () returning void
immutable functional object (int) returning double
functional object (int) returning double
functional object (int, lvalue refrence to const std::string, pointer to const char, double) returning double
Re[7]: char *(*(**foo[][8])())[]; - за сколько распарсите?
Здравствуйте, kov_serg, Вы писали:

_>http://coliru.stacked-crooked.com/a/895450c6e1f7529f


BTW, ты напрасно начал прикручивать списки формальных параметров к специализации для членов классов. Эта специализация является общей для любых нестатических членов — членов-данных и членов-функций.

_>А лямбды можно впихать?


Можно, но с ограничением: без auto в параметрах. Тип возвращаемого значения может быть auto.

http://coliru.stacked-crooked.com/a/dac5b55966f0dbbc

#include <iostream>
#include <string>

template <typename T, typename=void> struct TypeFormatter { std::string operator()() const { return "unknown type"; } };

template <typename...> struct FormatParamList;
template <> struct FormatParamList<> { std::string operator()() const {return {};} };
template <typename A, typename...X> struct FormatParamList<A, X...> { std::string operator()() const { return (TypeFormatter<A>{}() + ... + (", " + TypeFormatter<X>{}()));} };

template <typename> struct FunObjFormatter;
template <typename T, typename C, typename...A> struct FunObjFormatter<T(C::*)(A...)> { std::string operator()() const {return "functional object (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };
template <typename T, typename C, typename...A> struct FunObjFormatter<T(C::*)(A...) const> { std::string operator()() const {return "immutable functional object (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };

template <> struct TypeFormatter<void> { std::string operator()() const { return "void"; } };
template <> struct TypeFormatter<int> { std::string operator()() const { return "int"; } };
template <> struct TypeFormatter<char> { std::string operator()() const { return "char"; } };
template <> struct TypeFormatter<double> { std::string operator()() const { return "double"; } };
template <> struct TypeFormatter<std::string> { std::string operator()() const { return "std::string"; } };
template <typename T> struct TypeFormatter<const T> { std::string operator()() const { return "const " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T*> { std::string operator()() const { return "pointer to " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T&> { std::string operator()() const { return "lvalue refrence to " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T[]> { std::string operator()() const { return "array of unspecified size of " + TypeFormatter<T>()(); } };
template <typename T, size_t N> struct TypeFormatter<T[N]> { std::string operator()() const { return "array [" + std::to_string(N) + "] of " + TypeFormatter<T>()(); } };
template <typename T, typename C> struct TypeFormatter<T C::*> { std::string operator()() const {return "pointer to member of '" + TypeFormatter<C>()() + "' of type: " + TypeFormatter<T>()(); } };
template <typename T> struct TypeFormatter<T, std::void_t<typename T::TypeFormatter>> : T::TypeFormatter{};
template <typename T, typename...A> struct TypeFormatter<T(A...)> { std::string operator()() const {return "function (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };
template <typename T, typename...A> struct TypeFormatter<T(A...) const> { std::string operator()() const {return "immutable function (" + FormatParamList<A...>{}() + ") returning " + TypeFormatter<T>{}();} };
template <typename T> struct TypeFormatter<T, std::void_t<decltype(&T::operator())>> : FunObjFormatter<decltype(&T::operator())> {};

namespace NS {
    struct A { };
};
//using NS::A;
//typedef NS::A A;
struct A:NS::A {};

template <> struct TypeFormatter<A> { std::string operator()() const {return "struct A";} };

int main()
{
    std::cout << TypeFormatter< char*(*(**[][8])())[] >()() << std::endl;
    std::cout << TypeFormatter< int (*)(char,char*(*(**[][8])())[],int) >()() << std::endl;
    std::cout << TypeFormatter< int (*)() >()() << std::endl;
    std::cout << TypeFormatter< int A::* >()() << std::endl;

    std::cout << TypeFormatter<int(const char&, double&)>()() << std::endl;
    std::cout << TypeFormatter<int(const char&, double&) const>()() << std::endl;
    std::cout << TypeFormatter<int()>()() << std::endl;
    std::cout << TypeFormatter<int() const>()() << std::endl;

    auto l1 = []{};
    auto l2 = [](int) { return 3.14; };
    auto l3 = [](int) mutable { return 3.14; };
    auto l4 = [](int, const std::string&, const char*, double) mutable { return 3.14; };

    std::cout << TypeFormatter<decltype(l1)>()() << std::endl;
    std::cout << TypeFormatter<decltype(l2)>()() << std::endl;
    std::cout << TypeFormatter<decltype(l3)>()() << std::endl;
    std::cout << TypeFormatter<decltype(l4)>()() << std::endl;
}

array of unspecified size of array [8] of pointer to pointer to function () returning pointer to array of unspecified size of pointer to char
pointer to function (char, pointer to array [8] of pointer to pointer to function () returning pointer to array of unspecified size of pointer to char, int) returning int
pointer to function () returning int
pointer to member of 'struct A' of type: int
function (lvalue refrence to const char, lvalue refrence to double) returning int
immutable function (lvalue refrence to const char, lvalue refrence to double) returning int
function () returning int
immutable function () returning int
immutable functional object () returning void
immutable functional object (int) returning double
functional object (int) returning double
functional object (int, lvalue refrence to const std::string, pointer to const char, double) returning double