Skip to content

Commit

Permalink
Use constexpr (C++11) instead of GRNXX_CONSTEXPR.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Dec 5, 2012
1 parent cb72492 commit caf2e08
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/alpha/blob_vector.hpp
Expand Up @@ -503,7 +503,7 @@ class BlobVector {
return impl_ ? impl_->write_to(builder) : (builder << "n/a");
}

static GRNXX_CONSTEXPR uint64_t max_id() {
static constexpr uint64_t max_id() {
return BLOB_VECTOR_MAX_ID;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/alpha/vector.hpp
Expand Up @@ -277,19 +277,19 @@ class Vector {
return impl_ ? impl_->write_to(builder) : (builder << "n/a");
}

static GRNXX_CONSTEXPR uint64_t value_size() {
static constexpr uint64_t value_size() {
return sizeof(Value);
}
static GRNXX_CONSTEXPR uint64_t page_size() {
static constexpr uint64_t page_size() {
return PAGE_SIZE;
}
static GRNXX_CONSTEXPR uint64_t table_size() {
static constexpr uint64_t table_size() {
return TABLE_SIZE;
}
static GRNXX_CONSTEXPR uint64_t secondary_table_size() {
static constexpr uint64_t secondary_table_size() {
return SECONDARY_TABLE_SIZE;
}
static GRNXX_CONSTEXPR uint64_t max_id() {
static constexpr uint64_t max_id() {
return (PAGE_SIZE * TABLE_SIZE * SECONDARY_TABLE_SIZE) - 1;
}

Expand Down
50 changes: 25 additions & 25 deletions lib/duration.hpp
Expand Up @@ -25,36 +25,36 @@ namespace grnxx {

class Duration {
public:
GRNXX_CONSTEXPR Duration() : nanoseconds_(0) {}
explicit GRNXX_CONSTEXPR Duration(int64_t nanoseconds)
constexpr Duration() : nanoseconds_(0) {}
explicit constexpr Duration(int64_t nanoseconds)
: nanoseconds_(nanoseconds) {}

static GRNXX_CONSTEXPR Duration nanoseconds(int64_t nanoseconds) {
static constexpr Duration nanoseconds(int64_t nanoseconds) {
return Duration(nanoseconds);
}
static GRNXX_CONSTEXPR Duration microseconds(int64_t microseconds) {
static constexpr Duration microseconds(int64_t microseconds) {
return Duration(microseconds * 1000);
}
static GRNXX_CONSTEXPR Duration milliseconds(int64_t milliseconds) {
static constexpr Duration milliseconds(int64_t milliseconds) {
return Duration(milliseconds * 1000000);
}
static GRNXX_CONSTEXPR Duration seconds(int64_t seconds) {
static constexpr Duration seconds(int64_t seconds) {
return Duration(seconds * 1000000000);
}
static GRNXX_CONSTEXPR Duration minutes(int64_t minutes) {
static constexpr Duration minutes(int64_t minutes) {
return Duration(minutes * 1000000000 * 60);
}
static GRNXX_CONSTEXPR Duration hours(int64_t hours) {
static constexpr Duration hours(int64_t hours) {
return Duration(hours * 1000000000 * 60 * 60);
}
static GRNXX_CONSTEXPR Duration days(int64_t days) {
static constexpr Duration days(int64_t days) {
return Duration(days * 1000000000 * 60 * 60 * 24);
}
static GRNXX_CONSTEXPR Duration weeks(int64_t weeks) {
static constexpr Duration weeks(int64_t weeks) {
return Duration(weeks * 1000000000 * 60 * 60 * 24 * 7);
}

GRNXX_CONSTEXPR int64_t nanoseconds() const {
constexpr int64_t nanoseconds() const {
return nanoseconds_;
}
void set_nanoseconds(int64_t nanoseconds) {
Expand All @@ -69,10 +69,10 @@ class Duration {
// Copyable.
};

inline GRNXX_CONSTEXPR Duration operator+(Duration duration) {
inline constexpr Duration operator+(Duration duration) {
return duration;
}
inline GRNXX_CONSTEXPR Duration operator-(Duration duration) {
inline constexpr Duration operator-(Duration duration) {
return Duration(-duration.nanoseconds());
}

Expand Down Expand Up @@ -105,42 +105,42 @@ inline Duration &operator%=(Duration &lhs, Duration rhs) {
return lhs;
}

inline GRNXX_CONSTEXPR Duration operator+(Duration lhs, Duration rhs) {
inline constexpr Duration operator+(Duration lhs, Duration rhs) {
return Duration(lhs.nanoseconds() + rhs.nanoseconds());
}
inline GRNXX_CONSTEXPR Duration operator-(Duration lhs, Duration rhs) {
inline constexpr Duration operator-(Duration lhs, Duration rhs) {
return Duration(lhs.nanoseconds() - rhs.nanoseconds());
}
inline GRNXX_CONSTEXPR Duration operator*(Duration lhs, int64_t rhs) {
inline constexpr Duration operator*(Duration lhs, int64_t rhs) {
return Duration(lhs.nanoseconds() * rhs);
}
inline GRNXX_CONSTEXPR Duration operator*(int64_t lhs, Duration rhs) {
inline constexpr Duration operator*(int64_t lhs, Duration rhs) {
return Duration(lhs * rhs.nanoseconds());
}
inline GRNXX_CONSTEXPR Duration operator/(Duration lhs, int64_t rhs) {
inline constexpr Duration operator/(Duration lhs, int64_t rhs) {
return (rhs != 0) ? Duration(lhs.nanoseconds() / rhs) : Duration(0);
}
inline GRNXX_CONSTEXPR Duration operator%(Duration lhs, Duration rhs) {
inline constexpr Duration operator%(Duration lhs, Duration rhs) {
return (rhs.nanoseconds() != 0) ?
Duration(lhs.nanoseconds() % rhs.nanoseconds()) : Duration(0);
}

inline GRNXX_CONSTEXPR bool operator==(Duration lhs, Duration rhs) {
inline constexpr bool operator==(Duration lhs, Duration rhs) {
return lhs.nanoseconds() == rhs.nanoseconds();
}
inline GRNXX_CONSTEXPR bool operator!=(Duration lhs, Duration rhs) {
inline constexpr bool operator!=(Duration lhs, Duration rhs) {
return lhs.nanoseconds() != rhs.nanoseconds();
}
inline GRNXX_CONSTEXPR bool operator<(Duration lhs, Duration rhs) {
inline constexpr bool operator<(Duration lhs, Duration rhs) {
return lhs.nanoseconds() < rhs.nanoseconds();
}
inline GRNXX_CONSTEXPR bool operator<=(Duration lhs, Duration rhs) {
inline constexpr bool operator<=(Duration lhs, Duration rhs) {
return lhs.nanoseconds() <= rhs.nanoseconds();
}
inline GRNXX_CONSTEXPR bool operator>(Duration lhs, Duration rhs) {
inline constexpr bool operator>(Duration lhs, Duration rhs) {
return lhs.nanoseconds() > rhs.nanoseconds();
}
inline GRNXX_CONSTEXPR bool operator>=(Duration lhs, Duration rhs) {
inline constexpr bool operator>=(Duration lhs, Duration rhs) {
return lhs.nanoseconds() >= rhs.nanoseconds();
}

Expand Down
12 changes: 0 additions & 12 deletions lib/features.hpp
Expand Up @@ -118,28 +118,16 @@
# if GRNXX_CLANG_HAS(c_atomic)
# define GRNXX_HAS_CLANG_BUILTIN_ATOMIC
# endif // GRNXX_CLANG_HAS(c_atomic)
# if GRNXX_CLANG_HAS(cxx_constexpr)
# define GRNXX_HAS_CONSTEXPR
# endif // GRNXX_CLANG_HAS(cxx_constexpr)
#elif defined(GRNXX_GNUC)
# define GRNXX_HAS_GNUC_BUILTIN_CLZ
# if GRNXX_GNUC_VERSION >= GRNXX_GNUC_MAKE_VERSION(4, 2, 0)
# define GRNXX_HAS_GNUC_BUILTIN_SYNC
# endif // GRNXX_GNUC_VERSION >= GRNXX_GNUC_MAKE_VERSION(4, 2, 0)
# if GRNXX_GNUC_VERSION >= GRNXX_GNUC_MAKE_VERSION(4, 6, 0)
# define GRNXX_HAS_CONSTEXPR
# endif // GRNXX_GNUC_VERSION >= GRNXX_GNUC_MAKE_VERSION(4, 6, 0)
# if GRNXX_GNUC_VERSION >= GRNXX_GNUC_MAKE_VERSION(4, 7, 0)
# define GRNXX_HAS_GNUC_BUILTIN_ATOMIC
# endif // GRNXX_GNUC_VERSION >= GRNXX_GNUC_MAKE_VERSION(4, 7, 0)
#endif // defined(GRNXX_GNUC)

#ifdef GRNXX_HAS_CONSTEXPR
# define GRNXX_CONSTEXPR constexpr
#else // GRNXX_HAS_CONSTEXPR
# define GRNXX_CONSTEXPR
#endif // GRNXX_HAS_CONSTEXPR

// Source features.

#ifdef _POSIX_C_SOURCE
Expand Down
22 changes: 11 additions & 11 deletions lib/flags_impl.hpp
Expand Up @@ -28,30 +28,30 @@ class FlagsImpl {
typedef T Identifier;
typedef U Type;

GRNXX_CONSTEXPR FlagsImpl() : flags_(0) {}
GRNXX_CONSTEXPR FlagsImpl(const FlagsImpl &flags) : flags_(flags.flags_) {}
constexpr FlagsImpl() : flags_(0) {}
constexpr FlagsImpl(const FlagsImpl &flags) : flags_(flags.flags_) {}

GRNXX_CONSTEXPR explicit operator bool() const {
constexpr explicit operator bool() const {
return flags_ != 0;
}

GRNXX_CONSTEXPR FlagsImpl operator&(FlagsImpl rhs) const {
constexpr FlagsImpl operator&(FlagsImpl rhs) const {
return FlagsImpl(flags_ & rhs.flags_);
}
GRNXX_CONSTEXPR FlagsImpl operator|(FlagsImpl rhs) const {
constexpr FlagsImpl operator|(FlagsImpl rhs) const {
return FlagsImpl(flags_ | rhs.flags_);
}
GRNXX_CONSTEXPR FlagsImpl operator^(FlagsImpl rhs) const {
constexpr FlagsImpl operator^(FlagsImpl rhs) const {
return FlagsImpl(flags_ ^ rhs.flags_);
}
GRNXX_CONSTEXPR FlagsImpl operator~() const {
constexpr FlagsImpl operator~() const {
return FlagsImpl(~flags_);
}

GRNXX_CONSTEXPR bool operator==(FlagsImpl rhs) const {
constexpr bool operator==(FlagsImpl rhs) const {
return flags_ == rhs.flags_;
}
GRNXX_CONSTEXPR bool operator!=(FlagsImpl rhs) const {
constexpr bool operator!=(FlagsImpl rhs) const {
return flags_ == rhs.flags_;
}

Expand All @@ -68,14 +68,14 @@ class FlagsImpl {
return *this;
}

static GRNXX_CONSTEXPR FlagsImpl define(Type flags) {
static constexpr FlagsImpl define(Type flags) {
return FlagsImpl(flags);
}

private:
Type flags_;

explicit GRNXX_CONSTEXPR FlagsImpl(Type flags) : flags_(flags) {}
explicit constexpr FlagsImpl(Type flags) : flags_(flags) {}
};

} // namespace grnxx
Expand Down

0 comments on commit caf2e08

Please sign in to comment.