W
woodbrian77
I have this class:
class failure : public ::std::exception {
::std::string whatStr;
public:
explicit failure :std::string what_) : whatStr:std::move(what_))
{}
~failure () throw()
{}
char const* what () const throw()
{ return whatStr.c_str(); }
template <class T>
failure& operator<< (T val)
{
::std:stringstream ss;
ss << val;
whatStr.append(ss.str().c_str());
return *this;
}
};
If in some function I write this:
throw failure("Getaddrinfo: ") << gai_strerror(err); // << version
the executable/output from clang 3.2 is 96 bytes more than
if I write it this way:
throw failure:std::string("Getaddrinfo: ").append(gai_strerror(err)));
Using g++ 4.8.0 20130310, the executable for the "<< version"
is 120 bytes larger than the version that uses string::append.
While looking at this, one thing I tried was changing this:
failure& operator<< (T val)
to
failure& operator<< (T const& val)
but the size of one executable increased by about 9%
(over 5,000 bytes) when I tried that.
Do you suggest going with the append version? Any
other options? Tia.
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
class failure : public ::std::exception {
::std::string whatStr;
public:
explicit failure :std::string what_) : whatStr:std::move(what_))
{}
~failure () throw()
{}
char const* what () const throw()
{ return whatStr.c_str(); }
template <class T>
failure& operator<< (T val)
{
::std:stringstream ss;
ss << val;
whatStr.append(ss.str().c_str());
return *this;
}
};
If in some function I write this:
throw failure("Getaddrinfo: ") << gai_strerror(err); // << version
the executable/output from clang 3.2 is 96 bytes more than
if I write it this way:
throw failure:std::string("Getaddrinfo: ").append(gai_strerror(err)));
Using g++ 4.8.0 20130310, the executable for the "<< version"
is 120 bytes larger than the version that uses string::append.
While looking at this, one thing I tried was changing this:
failure& operator<< (T val)
to
failure& operator<< (T const& val)
but the size of one executable increased by about 9%
(over 5,000 bytes) when I tried that.
Do you suggest going with the append version? Any
other options? Tia.
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net