#include <string>#include <iostream>#include <tuple>
template<class type> constexpr std::string GetName(){ const char* start = __PRETTY_FUNCTION__; while(*start != '=') ++start; start += 2; size_t size = 0; while(start[size] != ';') ++size; return std::string(start, size);}int main(){ std::cout << GetName<void>() << std::endl; std::cout << GetName<int>() << std::endl; std::cout << GetName<decltype(0.3)>() << std::endl; std::cout << GetName<std::tuple<int, char>>() << std::endl; // Output: // void // int // double // std::tuple<int, char>}it provides a method for getting the programmatic name of a type
There is a `typename(type)` that returns a string proposed by some reflection proposal, isn't it?
Currently, __func__ is part of the c++ standard, however __PRETTY_FUNCTION__ (part of GCC and Clang) provides significantly more information about a function.
On Monday, October 31, 2016 at 11:01:38 PM UTC-7, ant...@perezexcelsior.com wrote:Currently, __func__ is part of the c++ standard, however __PRETTY_FUNCTION__ (part of GCC and Clang) provides significantly more information about a function.FWIW, my attitude toward __PRETTY_FUNCTION__ is the same as my attitude toward "#pragma once" (in the recent thread on that subject). I love it and evangelize its usage; but since it already exists and works great (for me and everyone I know), what's the benefit of standardizing it? Just to antagonize the MSVC dev team? ;) (MSVC supports something called _FUNCSIG but not __PRETTY_FUNCTION__. I'd love for them to get on that, but I don't think the ISO C++ committee is the right vector for MSVC feature requests.)
Em terça-feira, 1 de novembro de 2016, às 18:02:04 PDT, Nicol Bolas escreveu:
> That's the whole point of standardizing *anything*: so that all
> implementations can agree on what a particular thing means and how it will
> behave. You're basically saying that if GCC and Clang both implement some
> feature, then who cares if it's part of the standard or not.
>
> The C++ standard is not just for people using GCC or Clang.
Except that we'd standardise that it is a string literal of unknown and
arbitrary contents. What's the point of standardising that?
#include <iostream>
#include <utility>
template<class S, template<class...> class TT, class T = TT<S,S>>
const char *pretty(T && t = {S(), S()})
{ return __PRETTY_FUNCTION__; }
//{ return __FUNCSIG__; }
int main() {
std::cout << pretty<float, std::pair>() << std::endl;
// GCC: const char* pretty(T&&) [with S = float; TT = std::pair; T = std::pair<float, float>]
// Clang: const char *pretty(T &&) [S = float, TT = std::pair, T = std::__1::pair<float, float>]
// MSVC: const char *__cdecl pretty<float,struct std::pair,struct std::pair<float,float>>(struct std::pair<float,float> &&)
}--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c398c7ae-3490-457e-989c-9342bb9b580e%40isocpp.org.
Wouldn't we prefer something like this?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/fe332e9c-0c72-43e2-858f-f513cd83c746%40isocpp.org.
> That's just reflectionWhich just about the most requested feature and the most frustrating omission of the language.