This commit is contained in:
Victor Zverovich 2014-07-01 21:01:15 -07:00
parent b827a97fd6
commit c494c980b6

View File

@ -56,11 +56,10 @@
# define FMT_GCC_EXTENSION # define FMT_GCC_EXTENSION
#endif #endif
#if defined(__GNUC_LIBSTD__) && defined (__GNUC_LIBSTD_MINOR__) #ifdef __GNUC_LIBSTD__
# define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__) # define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__)
#endif #endif
// Compatibility with compilers other than clang.
#ifdef __has_feature #ifdef __has_feature
# define FMT_HAS_FEATURE(x) __has_feature(x) # define FMT_HAS_FEATURE(x) __has_feature(x)
#else #else
@ -73,19 +72,13 @@
# define FMT_HAS_BUILTIN(x) 0 # define FMT_HAS_BUILTIN(x) 0
#endif #endif
#ifdef _MSC_VER
# define FMT_MSC_VER _MSC_VER
#else
# define FMT_MSC_VER 0
#endif
#ifndef FMT_USE_VARIADIC_TEMPLATES #ifndef FMT_USE_VARIADIC_TEMPLATES
// Variadic templates are available in GCC since version 4.4 // Variadic templates are available in GCC since version 4.4
// (http://gcc.gnu.org/projects/cxx0x.html) and in Visual C++ // (http://gcc.gnu.org/projects/cxx0x.html) and in Visual C++
// since version 2013. // since version 2013.
# define FMT_USE_VARIADIC_TEMPLATES \ # define FMT_USE_VARIADIC_TEMPLATES \
(FMT_HAS_FEATURE(cxx_variadic_templates) || \ (FMT_HAS_FEATURE(cxx_variadic_templates) || \
(FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || FMT_MSC_VER >= 1800) (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || _MSC_VER >= 1800)
#endif #endif
#ifndef FMT_USE_RVALUE_REFERENCES #ifndef FMT_USE_RVALUE_REFERENCES
@ -96,7 +89,7 @@
# else # else
# define FMT_USE_RVALUE_REFERENCES \ # define FMT_USE_RVALUE_REFERENCES \
(FMT_HAS_FEATURE(cxx_rvalue_references) || \ (FMT_HAS_FEATURE(cxx_rvalue_references) || \
(FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || FMT_MSC_VER >= 1600) (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600)
# endif # endif
#endif #endif
@ -104,7 +97,7 @@
# include <utility> // for std::move # include <utility> // for std::move
#endif #endif
// Define FMT_USE_NOEXCEPT to make format use noexcept (C++11 feature). // Define FMT_USE_NOEXCEPT to make C++ Format use noexcept (C++11 feature).
#if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
(FMT_GCC_VERSION >= 408 && __cplusplus >= 201103) (FMT_GCC_VERSION >= 408 && __cplusplus >= 201103)
# define FMT_NOEXCEPT(expr) noexcept(expr) # define FMT_NOEXCEPT(expr) noexcept(expr)
@ -171,8 +164,8 @@ class BasicStringRef {
public: public:
/** /**
Constructs a string reference object from a C string and a size. Constructs a string reference object from a C string and a size.
If *size* is zero, which is the default, the size is computed with If *size* is zero, which is the default, the size is computed
`strlen`. automatically.
*/ */
BasicStringRef(const Char *s, std::size_t size = 0) : data_(s), size_(size) {} BasicStringRef(const Char *s, std::size_t size = 0) : data_(s), size_(size) {}
@ -242,10 +235,10 @@ class Array {
T *ptr_; T *ptr_;
T data_[SIZE]; T data_[SIZE];
void Grow(std::size_t size); void grow(std::size_t size);
// Free memory allocated by the array. // Free memory allocated by the array.
void Free() { void free() {
if (ptr_ != data_) delete [] ptr_; if (ptr_ != data_) delete [] ptr_;
} }
@ -268,7 +261,7 @@ class Array {
public: public:
Array() : size_(0), capacity_(SIZE), ptr_(data_) {} Array() : size_(0), capacity_(SIZE), ptr_(data_) {}
~Array() { Free(); } ~Array() { free(); }
#if FMT_USE_RVALUE_REFERENCES #if FMT_USE_RVALUE_REFERENCES
Array(Array &&other) { Array(Array &&other) {
@ -277,7 +270,7 @@ class Array {
Array& operator=(Array &&other) { Array& operator=(Array &&other) {
assert(this != &other); assert(this != &other);
Free(); free();
move(other); move(other);
return *this; return *this;
} }
@ -292,21 +285,21 @@ class Array {
// Resizes the array. If T is a POD type new elements are not initialized. // Resizes the array. If T is a POD type new elements are not initialized.
void resize(std::size_t new_size) { void resize(std::size_t new_size) {
if (new_size > capacity_) if (new_size > capacity_)
Grow(new_size); grow(new_size);
size_ = new_size; size_ = new_size;
} }
// Reserves space to store at least capacity elements. // Reserves space to store at least capacity elements.
void reserve(std::size_t capacity) { void reserve(std::size_t capacity) {
if (capacity > capacity_) if (capacity > capacity_)
Grow(capacity); grow(capacity);
} }
void clear() { size_ = 0; } void clear() { size_ = 0; }
void push_back(const T &value) { void push_back(const T &value) {
if (size_ == capacity_) if (size_ == capacity_)
Grow(size_ + 1); grow(size_ + 1);
ptr_[size_++] = value; ptr_[size_++] = value;
} }
@ -318,7 +311,7 @@ class Array {
}; };
template <typename T, std::size_t SIZE> template <typename T, std::size_t SIZE>
void Array<T, SIZE>::Grow(std::size_t size) { void Array<T, SIZE>::grow(std::size_t size) {
capacity_ = (std::max)(size, capacity_ + capacity_ / 2); capacity_ = (std::max)(size, capacity_ + capacity_ / 2);
T *p = new T[capacity_]; T *p = new T[capacity_];
std::copy(ptr_, ptr_ + size_, CheckPtr(p, capacity_)); std::copy(ptr_, ptr_ + size_, CheckPtr(p, capacity_));
@ -331,7 +324,7 @@ template <typename T, std::size_t SIZE>
void Array<T, SIZE>::append(const T *begin, const T *end) { void Array<T, SIZE>::append(const T *begin, const T *end) {
std::ptrdiff_t num_elements = end - begin; std::ptrdiff_t num_elements = end - begin;
if (size_ + num_elements > capacity_) if (size_ + num_elements > capacity_)
Grow(size_ + num_elements); grow(size_ + num_elements);
std::copy(begin, end, CheckPtr(ptr_, capacity_) + size_); std::copy(begin, end, CheckPtr(ptr_, capacity_) + size_);
size_ += num_elements; size_ += num_elements;
} }
@ -342,9 +335,6 @@ struct StringValue {
std::size_t size; std::size_t size;
}; };
template <typename Char>
class CharTraits;
template <typename Char> template <typename Char>
class BasicCharTraits { class BasicCharTraits {
public: public:
@ -355,6 +345,9 @@ class BasicCharTraits {
#endif #endif
}; };
template <typename Char>
class CharTraits;
template <> template <>
class CharTraits<char> : public BasicCharTraits<char> { class CharTraits<char> : public BasicCharTraits<char> {
private: private:
@ -714,9 +707,9 @@ class MakeArg : public internal::ArgInfo {
} }
}; };
class SystemErrorBase : public std::runtime_error { class RuntimeError : public std::runtime_error {
public: protected:
SystemErrorBase() : std::runtime_error("") {} RuntimeError() : std::runtime_error("") {}
}; };
} // namespace internal } // namespace internal
@ -728,7 +721,7 @@ class ArgList {
const internal::ArgInfo *args_; const internal::ArgInfo *args_;
std::size_t size_; std::size_t size_;
public: public:
ArgList() : size_(0) {} ArgList() : size_(0) {}
ArgList(const internal::ArgInfo *args, std::size_t size) ArgList(const internal::ArgInfo *args, std::size_t size)
: args_(args), size_(size) {} : args_(args), size_(size) {}
@ -1102,7 +1095,7 @@ inline StrFormatSpec<wchar_t> pad(
An error returned by an operating system or a language runtime, An error returned by an operating system or a language runtime,
for example a file opening error. for example a file opening error.
*/ */
class SystemError : public internal::SystemErrorBase { class SystemError : public internal::RuntimeError {
private: private:
void init(int error_code, StringRef format_str, const ArgList &args); void init(int error_code, StringRef format_str, const ArgList &args);