Remove operator<<(rvalue, T)
For MSVC this was a better than the rvalue->lvalue conversion
This commit is contained in:
parent
47f412bf8b
commit
3abcd60f96
41
fmt/format.h
41
fmt/format.h
@ -155,24 +155,6 @@ typedef __int64 intmax_t;
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FMT_USE_OSTREAM_RVALUE
|
|
||||||
// If non-zero, enables operator<< for BasicWriter&&, such that things like
|
|
||||||
// std::string s = (MemoryWriter() << "i = " << i).str();
|
|
||||||
// are possible.
|
|
||||||
//
|
|
||||||
// (See: http://cplusplus.github.io/LWG/lwg-active.html#1203)
|
|
||||||
//
|
|
||||||
// XXX:
|
|
||||||
// I don't know if FMT_USE_RVALUE_REFERENCES is the correct way to enable
|
|
||||||
// this... It works for g++ 6.3 and VC15, though.
|
|
||||||
//
|
|
||||||
# if FMT_USE_RVALUE_REFERENCES
|
|
||||||
# define FMT_USE_OSTREAM_RVALUE 1
|
|
||||||
# else
|
|
||||||
# define FMT_USE_OSTREAM_RVALUE 0
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Check if exceptions are disabled.
|
// Check if exceptions are disabled.
|
||||||
#if defined(__GNUC__) && !defined(__EXCEPTIONS)
|
#if defined(__GNUC__) && !defined(__EXCEPTIONS)
|
||||||
# define FMT_EXCEPTIONS 0
|
# define FMT_EXCEPTIONS 0
|
||||||
@ -2463,8 +2445,6 @@ class SystemError : public internal::RuntimeError {
|
|||||||
FMT_API void format_system_error(fmt::Writer &out, int error_code,
|
FMT_API void format_system_error(fmt::Writer &out, int error_code,
|
||||||
fmt::StringRef message) FMT_NOEXCEPT;
|
fmt::StringRef message) FMT_NOEXCEPT;
|
||||||
|
|
||||||
class BasicWriterBase {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
This template provides operations for formatting and writing data into
|
This template provides operations for formatting and writing data into
|
||||||
@ -2484,7 +2464,7 @@ class BasicWriterBase {};
|
|||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class BasicWriter : public BasicWriterBase {
|
class BasicWriter {
|
||||||
private:
|
private:
|
||||||
// Output buffer.
|
// Output buffer.
|
||||||
Buffer<Char> &buffer_;
|
Buffer<Char> &buffer_;
|
||||||
@ -2929,25 +2909,6 @@ inline BasicWriter<Char> &operator<<(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FMT_USE_OSTREAM_RVALUE
|
|
||||||
// http://cplusplus.github.io/LWG/lwg-active.html#1203
|
|
||||||
//
|
|
||||||
// For:
|
|
||||||
// std::string s = (MemoryWriter() << "i = " << i).str();
|
|
||||||
template <
|
|
||||||
typename WriterT,
|
|
||||||
typename T,
|
|
||||||
typename = typename std::enable_if<
|
|
||||||
!std::is_lvalue_reference<WriterT>::value
|
|
||||||
&& std::is_base_of<BasicWriterBase, WriterT>::value
|
|
||||||
>::type
|
|
||||||
>
|
|
||||||
inline WriterT &&operator<<(WriterT &&w, const T &value) {
|
|
||||||
w << value;
|
|
||||||
return std::move(w);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
template <typename StrChar>
|
template <typename StrChar>
|
||||||
typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str(
|
typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str(
|
||||||
|
|||||||
@ -534,10 +534,6 @@ TEST(WriterTest, Stream) {
|
|||||||
//w << std::wstring(wcs);
|
//w << std::wstring(wcs);
|
||||||
w << fmt::StrFormatSpec<wchar_t>(wcs, 3, ' ');
|
w << fmt::StrFormatSpec<wchar_t>(wcs, 3, ' ');
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FMT_USE_OSTREAM_RVALUE
|
|
||||||
EXPECT_EQ("i = 123", (MemoryWriter() << "i = " << 123).str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(WWriterTest, Stream) {
|
TEST(WWriterTest, Stream) {
|
||||||
@ -576,10 +572,6 @@ TEST(WWriterTest, Stream) {
|
|||||||
EXPECT_EQ(L"ncs", (WMemoryWriter() << fmt::StringRef(ncs)).str());
|
EXPECT_EQ(L"ncs", (WMemoryWriter() << fmt::StringRef(ncs)).str());
|
||||||
EXPECT_EQ(L"ncs", (WMemoryWriter() << std::string(ncs)).str());
|
EXPECT_EQ(L"ncs", (WMemoryWriter() << std::string(ncs)).str());
|
||||||
EXPECT_EQ(L"ncs", (WMemoryWriter() << fmt::StrFormatSpec<char>(ncs, 3, ' ')).str());
|
EXPECT_EQ(L"ncs", (WMemoryWriter() << fmt::StrFormatSpec<char>(ncs, 3, ' ')).str());
|
||||||
|
|
||||||
#if FMT_USE_OSTREAM_RVALUE
|
|
||||||
EXPECT_EQ(L"i = 123", (WMemoryWriter() << L"i = " << 123).str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ArrayWriterTest, Ctor) {
|
TEST(ArrayWriterTest, Ctor) {
|
||||||
|
|||||||
@ -145,11 +145,6 @@ TEST(OStreamTest, WriteUserDefinedTypeToOStream) {
|
|||||||
w << "The answer is " << u;
|
w << "The answer is " << u;
|
||||||
fmt::internal::write(os, w);
|
fmt::internal::write(os, w);
|
||||||
EXPECT_EQ("The answer is 42", os.str());
|
EXPECT_EQ("The answer is 42", os.str());
|
||||||
|
|
||||||
#if FMT_USE_OSTREAM_RVALUE
|
|
||||||
EXPECT_EQ("The answer is 42",
|
|
||||||
(fmt::MemoryWriter() << "The answer is " << UserDefinedTest()).str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(OStreamTest, WriteToOStreamMaxSize) {
|
TEST(OStreamTest, WriteToOStreamMaxSize) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user