n***@gmail.com
2018-10-10 12:21:54 UTC
Currently std::to_string can be used as a customization point by the
following:
using std::to_string
std::string a = to_string(some_object);
However, using "using" every time is tedious. We can add a wrapper to that:
#include<iostream>
template< typename T>
std::string as_string(T &&o) {
using std::to_string;
returnto_string(std::forward<T>(o));
}
classA {};
std::string to_string(constA &a) {
return"hello";
}
intmain() {
std::cout << as_string(1) << as_string(A{});
return0;
}
Doing that in each project is just a boilerplate. Is there any proposal to
standardize something like that? It does not require any language feature,
but would be nice to have as a part of a standard library. It can be used
if we want to add some sort of possibility to add to_string conversion to
things like enums or any other built-in construct.
following:
using std::to_string
std::string a = to_string(some_object);
However, using "using" every time is tedious. We can add a wrapper to that:
#include<iostream>
template< typename T>
std::string as_string(T &&o) {
using std::to_string;
returnto_string(std::forward<T>(o));
}
classA {};
std::string to_string(constA &a) {
return"hello";
}
intmain() {
std::cout << as_string(1) << as_string(A{});
return0;
}
Doing that in each project is just a boilerplate. Is there any proposal to
standardize something like that? It does not require any language feature,
but would be nice to have as a part of a standard library. It can be used
if we want to add some sort of possibility to add to_string conversion to
things like enums or any other built-in construct.
--
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-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2e3b84ef-15c8-42d4-a5de-5ce9ee3c078c%40isocpp.org.
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-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2e3b84ef-15c8-42d4-a5de-5ce9ee3c078c%40isocpp.org.