Skip to content

Commit

Permalink
Remove FMT_USE_RVALUE_REFERENCES
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 22, 2018
1 parent 5befe65 commit c178ab4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 126 deletions.
7 changes: 0 additions & 7 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ FMT_END_NAMESPACE
# define FMT_USE_TRAILING_RETURN 0
#endif

#if FMT_HAS_GXX_CXX11 || FMT_HAS_FEATURE(cxx_rvalue_references) || \
FMT_MSC_VER >= 1600
# define FMT_USE_RVALUE_REFERENCES 1
#else
# define FMT_USE_RVALUE_REFERENCES 0
#endif

#ifndef FMT_USE_GRISU
# define FMT_USE_GRISU 0
#endif
Expand Down
98 changes: 0 additions & 98 deletions include/fmt/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,50 +139,6 @@ class buffered_file {
// Destroys the object closing the file it represents if any.
FMT_API ~buffered_file() FMT_DTOR_NOEXCEPT;

#if !FMT_USE_RVALUE_REFERENCES
// Emulate a move constructor and a move assignment operator if rvalue
// references are not supported.

private:
// A proxy object to emulate a move constructor.
// It is private to make it impossible call operator Proxy directly.
struct Proxy {
FILE *file;
};

public:
// A "move constructor" for moving from a temporary.
buffered_file(Proxy p) FMT_NOEXCEPT : file_(p.file) {}

// A "move constructor" for moving from an lvalue.
buffered_file(buffered_file &f) FMT_NOEXCEPT : file_(f.file_) {
f.file_ = FMT_NULL;
}

// A "move assignment operator" for moving from a temporary.
buffered_file &operator=(Proxy p) {
close();
file_ = p.file;
return *this;
}

// A "move assignment operator" for moving from an lvalue.
buffered_file &operator=(buffered_file &other) {
close();
file_ = other.file_;
other.file_ = FMT_NULL;
return *this;
}

// Returns a proxy object for moving from a temporary:
// buffered_file file = buffered_file(...);
operator Proxy() FMT_NOEXCEPT {
Proxy p = {file_};
file_ = FMT_NULL;
return p;
}

#else
private:
buffered_file(const buffered_file &) = delete;
void operator=(const buffered_file &) = delete;
Expand All @@ -199,7 +155,6 @@ class buffered_file {
other.file_ = FMT_NULL;
return *this;
}
#endif

// Opens a file.
FMT_API buffered_file(cstring_view filename, cstring_view mode);
Expand Down Expand Up @@ -251,50 +206,6 @@ class file {
// Opens a file and constructs a file object representing this file.
FMT_API file(cstring_view path, int oflag);

#if !FMT_USE_RVALUE_REFERENCES
// Emulate a move constructor and a move assignment operator if rvalue
// references are not supported.

private:
// A proxy object to emulate a move constructor.
// It is private to make it impossible call operator Proxy directly.
struct Proxy {
int fd;
};

public:
// A "move constructor" for moving from a temporary.
file(Proxy p) FMT_NOEXCEPT : fd_(p.fd) {}

// A "move constructor" for moving from an lvalue.
file(file &other) FMT_NOEXCEPT : fd_(other.fd_) {
other.fd_ = -1;
}

// A "move assignment operator" for moving from a temporary.
file &operator=(Proxy p) {
close();
fd_ = p.fd;
return *this;
}

// A "move assignment operator" for moving from an lvalue.
file &operator=(file &other) {
close();
fd_ = other.fd_;
other.fd_ = -1;
return *this;
}

// Returns a proxy object for moving from a temporary:
// file f = file(...);
operator Proxy() FMT_NOEXCEPT {
Proxy p = {fd_};
fd_ = -1;
return p;
}

#else
private:
file(const file &) = delete;
void operator=(const file &) = delete;
Expand All @@ -310,7 +221,6 @@ class file {
other.fd_ = -1;
return *this;
}
#endif

// Destroys the object closing the file it represents if any.
FMT_API ~file() FMT_DTOR_NOEXCEPT;
Expand Down Expand Up @@ -410,12 +320,4 @@ class Locale {
#endif // FMT_LOCALE
FMT_END_NAMESPACE

#if !FMT_USE_RVALUE_REFERENCES
namespace std {
// For compatibility with C++98.
inline fmt::buffered_file &move(fmt::buffered_file &f) { return f; }
inline fmt::file &move(fmt::file &f) { return f; }
}
#endif

#endif // FMT_POSIX_H_
28 changes: 11 additions & 17 deletions test/mock-allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,31 @@ class AllocatorRef {
private:
Allocator *alloc_;

void move(AllocatorRef &other) {
alloc_ = other.alloc_;
other.alloc_ = nullptr;
}

public:
typedef typename Allocator::value_type value_type;

explicit AllocatorRef(Allocator *alloc = nullptr) : alloc_(alloc) {}

AllocatorRef(const AllocatorRef &other) : alloc_(other.alloc_) {}
AllocatorRef(AllocatorRef &&other) { move(other); }

AllocatorRef& operator=(const AllocatorRef &other) {
alloc_ = other.alloc_;
AllocatorRef& operator=(AllocatorRef &&other) {
assert(this != &other);
move(other);
return *this;
}

#if FMT_USE_RVALUE_REFERENCES
private:
void move(AllocatorRef &other) {
AllocatorRef& operator=(const AllocatorRef &other) {
alloc_ = other.alloc_;
other.alloc_ = nullptr;
}

public:
AllocatorRef(AllocatorRef &&other) {
move(other);
}

AllocatorRef& operator=(AllocatorRef &&other) {
assert(this != &other);
move(other);
return *this;
}
#endif

public:
Allocator *get() const { return alloc_; }

value_type* allocate(std::size_t n) {
Expand Down
4 changes: 0 additions & 4 deletions test/util-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ TEST(MemoryBufferTest, Ctor) {
EXPECT_EQ(123u, buffer.capacity());
}

#if FMT_USE_RVALUE_REFERENCES

typedef AllocatorRef< std::allocator<char> > TestAllocator;

static void check_move_buffer(const char *str,
Expand Down Expand Up @@ -304,8 +302,6 @@ TEST(MemoryBufferTest, MoveAssignment) {
EXPECT_GT(buffer2.capacity(), 5u);
}

#endif // FMT_USE_RVALUE_REFERENCES

TEST(MemoryBufferTest, Grow) {
typedef AllocatorRef< MockAllocator<int> > Allocator;
typedef basic_memory_buffer<int, 10, Allocator> Base;
Expand Down

0 comments on commit c178ab4

Please sign in to comment.