From 25e19b5810951357cb382016e39fba5efac68e16 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 23 May 2017 12:50:51 +1000 Subject: [PATCH] build: use explicit constructors --- adapter.hpp | 6 +++--- alloc/allocator.hpp | 2 +- alloc/arena.hpp | 2 +- cmdopt.hpp | 8 ++++---- except.hpp | 10 +++++----- fixup/experimental/filesystem.hpp | 2 +- format.hpp | 2 +- io.hpp | 4 ++-- json/except.hpp | 6 +++--- library_win32.hpp | 2 +- memory/deleter.hpp | 2 +- rand/lcg.hpp | 2 +- rand/mwc64x.hpp | 2 +- rand/xorshift.hpp | 2 +- signal.hpp | 2 +- stream.hpp | 18 +++++++++--------- time.hpp | 4 ++-- 17 files changed, 38 insertions(+), 38 deletions(-) diff --git a/adapter.hpp b/adapter.hpp index 5a69a46e..a5b87a05 100644 --- a/adapter.hpp +++ b/adapter.hpp @@ -26,7 +26,7 @@ namespace util::adapter { // reverse a container for range-based-for template struct reverse { - reverse (T &_target): + explicit reverse (T &_target): m_target (_target) { ; } @@ -49,7 +49,7 @@ namespace util::adapter { struct indices { using typename T::size_type; - indices (T &_target): + explicit indices (T &_target): m_target (_target) { ; } @@ -79,7 +79,7 @@ namespace util::adapter { using reference = typename std::iterator_traits>::reference; using value_type = typename std::iterator_traits>::value_type; - scalar (It _inner): + explicit scalar (It _inner): m_inner (_inner) { ; } diff --git a/alloc/allocator.hpp b/alloc/allocator.hpp index efb302d9..cca7cfc6 100644 --- a/alloc/allocator.hpp +++ b/alloc/allocator.hpp @@ -28,7 +28,7 @@ namespace util::alloc { typedef T value_type; template - allocator (Args&& ...args); + explicit allocator (Args&& ...args); T* allocate (size_t count); void deallocate (T*, size_t count); diff --git a/alloc/arena.hpp b/alloc/arena.hpp index 82423844..a61939bb 100644 --- a/alloc/arena.hpp +++ b/alloc/arena.hpp @@ -26,7 +26,7 @@ namespace util::alloc { template class arena { public: - arena (T &store); + explicit arena (T &store); //--------------------------------------------------------------------- template diff --git a/cmdopt.hpp b/cmdopt.hpp index 27575c29..9dd29c7e 100644 --- a/cmdopt.hpp +++ b/cmdopt.hpp @@ -117,7 +117,7 @@ namespace util::cmdopt { class bytes : public value { public: - bytes (size_t &_value): value (_value) { } + explicit bytes (size_t &_value): value (_value) { } using value::execute; void execute (const char *restrict) override; @@ -168,7 +168,7 @@ namespace util::cmdopt { //------------------------------------------------------------------------- class invalid_key : public error { public: - invalid_key (std::string _key); + explicit invalid_key (std::string _key); const char* what (void) const noexcept override; private: @@ -178,7 +178,7 @@ namespace util::cmdopt { //------------------------------------------------------------------------- class invalid_value : public error { public: - invalid_value (std::string _value); + explicit invalid_value (std::string _value); const char* what (void) const noexcept override; private: @@ -200,7 +200,7 @@ namespace util::cmdopt { //------------------------------------------------------------------------- class unhandled_argument : public error { public: - unhandled_argument (int index); + explicit unhandled_argument (int index); const char* what (void) const noexcept override; int index (void) const noexcept; diff --git a/except.hpp b/except.hpp index 49b74aa3..2d33203b 100644 --- a/except.hpp +++ b/except.hpp @@ -25,7 +25,7 @@ namespace util { class input_error : public std::runtime_error { public: - input_error (const std::string &_what): + explicit input_error (const std::string &_what): runtime_error (_what) { ; } }; @@ -33,7 +33,7 @@ namespace util { class output_error : public std::runtime_error { public: - output_error (const std::string &_what): + explicit output_error (const std::string &_what): runtime_error (_what) { ; } }; @@ -41,7 +41,7 @@ namespace util { class unavailable_error : public std::runtime_error { public: - unavailable_error (const std::string &_what): + explicit unavailable_error (const std::string &_what): runtime_error (_what) { ; } }; @@ -50,7 +50,7 @@ namespace util { /// An exception class used for reporting errors signalled by errno. class errno_error : public std::runtime_error { public: - errno_error (int code); + explicit errno_error (int code); errno_error (); int code (void) const; @@ -73,7 +73,7 @@ namespace util { namespace util { class win32_error : public std::runtime_error { public: - win32_error (DWORD _code); + explicit win32_error (DWORD _code); win32_error (); DWORD code (void) const; diff --git a/fixup/experimental/filesystem.hpp b/fixup/experimental/filesystem.hpp index 541ddf09..9cc92c6d 100644 --- a/fixup/experimental/filesystem.hpp +++ b/fixup/experimental/filesystem.hpp @@ -29,7 +29,7 @@ namespace std::experimental::filesystem { static constexpr value_type preferred_separator = '/'; path (); - path (const path&); + explicit path (const path&); template path (const Source &s): diff --git a/format.hpp b/format.hpp index d7b69d27..48dd6103 100644 --- a/format.hpp +++ b/format.hpp @@ -53,7 +53,7 @@ namespace util::format { public: using value_type = ValueT; - invalid_specifier (char specifier); + explicit invalid_specifier (char specifier); char specifier (void) const; diff --git a/io.hpp b/io.hpp index 26ac77a5..521109b5 100644 --- a/io.hpp +++ b/io.hpp @@ -69,7 +69,7 @@ namespace util { //------------------------------------------------------------------------- template struct indented { - indented (const T &_data); + explicit indented (const T &_data); const T &data; }; @@ -100,7 +100,7 @@ namespace util { //------------------------------------------------------------------------- class path_error : public std::runtime_error { public: - path_error (const std::experimental::filesystem::path &path); + explicit path_error (const std::experimental::filesystem::path &path); const std::experimental::filesystem::path& path (void) const noexcept; diff --git a/json/except.hpp b/json/except.hpp index b9244480..4a1e69fe 100644 --- a/json/except.hpp +++ b/json/except.hpp @@ -24,7 +24,7 @@ namespace json { /// The base class for all exceptions throw directly by the json namespace. struct error : public std::runtime_error { - error (const std::string &what): + explicit error (const std::string &what): runtime_error (what) { ; } }; @@ -32,7 +32,7 @@ namespace json { /// Base class for all type conversion errors struct type_error : public error { - type_error (const std::string &what): + explicit type_error (const std::string &what): error (what) { ; } }; @@ -51,7 +51,7 @@ namespace json { /// Base class for errors thrown during schema validation struct schema_error : public error { - schema_error (const std::string &what): + explicit schema_error (const std::string &what): error (what) { ; } }; diff --git a/library_win32.hpp b/library_win32.hpp index 320b2a85..14f17c1a 100644 --- a/library_win32.hpp +++ b/library_win32.hpp @@ -25,7 +25,7 @@ namespace util { namespace detail::win32 { class library { public: - library (const std::experimental::filesystem::path&); + explicit library (const std::experimental::filesystem::path&); ~library (); void* symbol (const char *name); diff --git a/memory/deleter.hpp b/memory/deleter.hpp index ceaf030a..5921afcf 100644 --- a/memory/deleter.hpp +++ b/memory/deleter.hpp @@ -25,7 +25,7 @@ namespace util::memory { public: using func_t = std::function; - func_deleter (func_t _func): + explicit func_deleter (func_t _func): m_func (_func) { ; } diff --git a/rand/lcg.hpp b/rand/lcg.hpp index 75a2d309..91ea1b9a 100644 --- a/rand/lcg.hpp +++ b/rand/lcg.hpp @@ -35,7 +35,7 @@ namespace util::rand { static_assert (std::is_unsigned::value, "LCG generates integer overflow which is undefined behaviour for signed types"); - lcg (T seed); + explicit lcg (T seed); result_type operator() (void); diff --git a/rand/mwc64x.hpp b/rand/mwc64x.hpp index 066b5570..aedf7bc6 100644 --- a/rand/mwc64x.hpp +++ b/rand/mwc64x.hpp @@ -30,7 +30,7 @@ namespace util::rand { using value_type = uint32_t; using seed_type = uint64_t; - mwc64x (seed_type); + explicit mwc64x (seed_type); value_type operator() (void); diff --git a/rand/xorshift.hpp b/rand/xorshift.hpp index e5a57369..64fdab10 100644 --- a/rand/xorshift.hpp +++ b/rand/xorshift.hpp @@ -28,7 +28,7 @@ namespace util::rand { public: using result_type = T; - xorshift (T seed); + explicit xorshift (T seed); result_type operator() (void); diff --git a/signal.hpp b/signal.hpp index aed2ea45..17e7dfde 100644 --- a/signal.hpp +++ b/signal.hpp @@ -109,7 +109,7 @@ namespace util { template class value_signal : public signal { public: - value_signal (T); + explicit value_signal (T); value_signal () = default; operator const T&() const; diff --git a/stream.hpp b/stream.hpp index b438b2de..5a9c4603 100644 --- a/stream.hpp +++ b/stream.hpp @@ -22,15 +22,15 @@ namespace util::stream { namespace scoped { - #define SCOPED(NAME,TYPE) \ - class NAME { \ - public: \ - NAME (std::ios_base&); \ - ~NAME (); \ - \ - private: \ - std::ios_base &m_ios; \ - TYPE m_state; \ + #define SCOPED(NAME,TYPE) \ + class NAME { \ + public: \ + explicit NAME (std::ios_base&); \ + ~NAME (); \ + \ + private: \ + std::ios_base &m_ios; \ + TYPE m_state; \ } SCOPED(flags, std::ios_base::fmtflags); diff --git a/time.hpp b/time.hpp index a2c3d800..5fcca2b6 100644 --- a/time.hpp +++ b/time.hpp @@ -48,7 +48,7 @@ namespace util { // ------------------------------------------------------------------------ class period_query { public: - period_query (float seconds); + explicit period_query (float seconds); bool poll (void); @@ -62,7 +62,7 @@ namespace util { // ------------------------------------------------------------------------ class rate_limiter { public: - rate_limiter (unsigned rate); + explicit rate_limiter (unsigned rate); void poll (void);