susumu.yata
null+****@clear*****
Thu Dec 6 14:58:10 JST 2012
susumu.yata 2012-12-06 14:58:10 +0900 (Thu, 06 Dec 2012) New Revision: ae7f9ea176421306e99b2f02eb4f2e6ee4a2ba7e https://github.com/groonga/grnxx/commit/ae7f9ea176421306e99b2f02eb4f2e6ee4a2ba7e Log: Prefer constexpr. Modified files: lib/logger.cpp lib/logger.hpp lib/recycler.hpp lib/string_builder.hpp lib/string_format.hpp Modified: lib/logger.cpp (+1 -1) =================================================================== --- lib/logger.cpp 2012-12-06 14:41:55 +0900 (6aa3db1) +++ lib/logger.cpp 2012-12-06 14:58:10 +0900 (b20621c) @@ -35,7 +35,7 @@ class LoggerSingleton { if (!instance_) { return false; } - static const LoggerFlags OUTPUT_FLAGS = + static constexpr LoggerFlags OUTPUT_FLAGS = LOGGER_ENABLE_COUT | LOGGER_ENABLE_CERR | LOGGER_ENABLE_CLOG; const LoggerFlags flags = Logger::flags(); if (!(flags & OUTPUT_FLAGS)) { Modified: lib/logger.hpp (+9 -9) =================================================================== --- lib/logger.hpp 2012-12-06 14:41:55 +0900 (7fc9191) +++ lib/logger.hpp 2012-12-06 14:58:10 +0900 (05f0dda) @@ -33,7 +33,7 @@ namespace grnxx { -const size_t LOGGER_BUF_SIZE = 4096; +constexpr size_t LOGGER_BUF_SIZE = 4096; enum LoggerLevel { ERROR_LOGGER = 0x0000, @@ -44,16 +44,16 @@ enum LoggerLevel { class LoggerFlagsIdentifier {}; typedef FlagsImpl<LoggerFlagsIdentifier> LoggerFlags; -const LoggerFlags LOGGER_WITH_DATE_TIME = LoggerFlags::define(0x0001); -const LoggerFlags LOGGER_WITH_LOCATION = LoggerFlags::define(0x0002); -const LoggerFlags LOGGER_WITH_LEVEL = LoggerFlags::define(0x0004); -const LoggerFlags LOGGER_WITH_ALL = LoggerFlags::define(0x0007); +constexpr LoggerFlags LOGGER_WITH_DATE_TIME = LoggerFlags::define(0x0001); +constexpr LoggerFlags LOGGER_WITH_LOCATION = LoggerFlags::define(0x0002); +constexpr LoggerFlags LOGGER_WITH_LEVEL = LoggerFlags::define(0x0004); +constexpr LoggerFlags LOGGER_WITH_ALL = LoggerFlags::define(0x0007); -const LoggerFlags LOGGER_ENABLE_COUT = LoggerFlags::define(0x0100); -const LoggerFlags LOGGER_ENABLE_CERR = LoggerFlags::define(0x0200); -const LoggerFlags LOGGER_ENABLE_CLOG = LoggerFlags::define(0x0400); +constexpr LoggerFlags LOGGER_ENABLE_COUT = LoggerFlags::define(0x0100); +constexpr LoggerFlags LOGGER_ENABLE_CERR = LoggerFlags::define(0x0200); +constexpr LoggerFlags LOGGER_ENABLE_CLOG = LoggerFlags::define(0x0400); -const LoggerFlags LOGGER_ENABLE_AUTO_RESIZE = LoggerFlags::define(0x1000); +constexpr LoggerFlags LOGGER_ENABLE_AUTO_RESIZE = LoggerFlags::define(0x1000); class Logger { public: Modified: lib/recycler.hpp (+7 -9) =================================================================== --- lib/recycler.hpp 2012-12-06 14:41:55 +0900 (60312ec) +++ lib/recycler.hpp 2012-12-06 14:58:10 +0900 (9ca229d) @@ -22,23 +22,21 @@ namespace grnxx { -const uint8_t RECYCLER_STAMP_BUF_SIZE_BITS = 6; -const uint16_t RECYCLER_STAMP_BUF_SIZE = +constexpr uint8_t RECYCLER_STAMP_BUF_SIZE_BITS = 6; +constexpr uint16_t RECYCLER_STAMP_BUF_SIZE = uint16_t(1 << RECYCLER_STAMP_BUF_SIZE_BITS); -const uint16_t RECYCLER_STAMP_MASK = RECYCLER_STAMP_BUF_SIZE - 1; +constexpr uint16_t RECYCLER_STAMP_MASK = RECYCLER_STAMP_BUF_SIZE - 1; -const uint32_t RECYCLER_STAMP_COUNT_PER_UPDATE = 512; +constexpr uint32_t RECYCLER_STAMP_COUNT_PER_UPDATE = 512; -const Time RECYCLER_FUTURE_TIME = Time(std::numeric_limits<int64_t>::max()); +constexpr Time RECYCLER_FUTURE_TIME = Time::max(); class Recycler { public: Recycler() : count_(), stamp_pair_(), frozen_duration_(), times_() {} explicit Recycler(Duration frozen_duration) - : count_(0), stamp_pair_(), frozen_duration_(frozen_duration), times_() { - stamp_pair_.current = 0; - stamp_pair_.threshold = 0; - + : count_(0), stamp_pair_{ 0, 0 }, + frozen_duration_(frozen_duration), times_() { times_[0] = Time(0); for (uint16_t i = 1; i < RECYCLER_STAMP_BUF_SIZE; ++i) { times_[i] = Time(RECYCLER_FUTURE_TIME); Modified: lib/string_builder.hpp (+2 -2) =================================================================== --- lib/string_builder.hpp 2012-12-06 14:41:55 +0900 (9aa9bbc) +++ lib/string_builder.hpp 2012-12-06 14:58:10 +0900 (6125fbf) @@ -24,12 +24,12 @@ namespace grnxx { -const size_t STRING_BUILDER_BUF_SIZE_MIN = 64; +constexpr size_t STRING_BUILDER_BUF_SIZE_MIN = 64; class StringBuilderFlagsIdentifier {}; typedef FlagsImpl<StringBuilderFlagsIdentifier> StringBuilderFlags; -const StringBuilderFlags STRING_BUILDER_AUTO_RESIZE = +constexpr StringBuilderFlags STRING_BUILDER_AUTO_RESIZE = StringBuilderFlags::define(0x01); class StringBuilder { Modified: lib/string_format.hpp (+19 -20) =================================================================== --- lib/string_format.hpp 2012-12-06 14:41:55 +0900 (e35e54b) +++ lib/string_format.hpp 2012-12-06 14:58:10 +0900 (94ae972) @@ -32,61 +32,60 @@ enum StringFormatAlignmentAttribute { template <typename T> class StringFormatAlignment { public: - StringFormatAlignment(const T &value, size_t width, int pad, - StringFormatAlignmentAttribute attribute) + constexpr StringFormatAlignment(const T &value, size_t width, int pad, + StringFormatAlignmentAttribute attribute) : value_(value), width_(width), pad_(pad), attribute_(attribute) {} - const T &value() const { + constexpr const T &value() { return value_; } - size_t width() const { + constexpr size_t width() { return width_; } - int pad() const { + constexpr int pad() { return pad_; } - StringFormatAlignmentAttribute attribute() const { + constexpr StringFormatAlignmentAttribute attribute() { return attribute_; } private: const T &value_; - const size_t width_; - const int pad_; - const StringFormatAlignmentAttribute attribute_; + size_t width_; + int pad_; + StringFormatAlignmentAttribute attribute_; }; class StringFormat { public: + StringFormat() = delete; + ~StringFormat() = delete; + + StringFormat(const StringFormat &) = delete; + StringFormat &operator=(const StringFormat &) = delete; + template <typename T> - static StringFormatAlignment<T> align_left( + static constexpr StringFormatAlignment<T> align_left( const T &value, size_t width, int pad = ' ') { return align<T>(value, width, pad, STRING_FORMAT_ALIGNMENT_LEFT); } template <typename T> - static StringFormatAlignment<T> align_right( + static constexpr StringFormatAlignment<T> align_right( const T &value, size_t width, int pad = ' ') { return align<T>(value, width, pad, STRING_FORMAT_ALIGNMENT_RIGHT); } template <typename T> - static StringFormatAlignment<T> align_center( + static constexpr StringFormatAlignment<T> align_center( const T &value, size_t width, int pad = ' ') { return align<T>(value, width, pad, STRING_FORMAT_ALIGNMENT_CENTER); } template <typename T> - static StringFormatAlignment<T> align( + static constexpr StringFormatAlignment<T> align( const T &value, size_t width, int pad = ' ', StringFormatAlignmentAttribute attribute = STRING_FORMAT_ALIGNMENT_LEFT) { return StringFormatAlignment<T>(value, width, pad, attribute); } - - private: - StringFormat(); - ~StringFormat(); - - StringFormat(const StringFormat &); - StringFormat &operator=(const StringFormat &); }; template <typename T> -------------- next part -------------- HTML����������������������������... ダウンロード