diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-17T15·31+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-17T15·31+0100 |
commit | 0f2cf531f705d370321843e5ba9135b2ebdb5d19 (patch) | |
tree | 256feb13963a849ed96e89228fa05454c2a22363 /third_party/nix/src/libutil/types.hh | |
parent | 65a1aae98ce5a237c9643e639e550c8b0c0be7f1 (diff) |
style(3p/nix): Reformat project in Google C++ style r/740
Reformatted with: fd . -e hh -e cc | xargs clang-format -i
Diffstat (limited to 'third_party/nix/src/libutil/types.hh')
-rw-r--r-- | third_party/nix/src/libutil/types.hh | 145 |
1 files changed, 57 insertions, 88 deletions
diff --git a/third_party/nix/src/libutil/types.hh b/third_party/nix/src/libutil/types.hh index 92bf469b5c6f..ab2fee392286 100644 --- a/third_party/nix/src/libutil/types.hh +++ b/third_party/nix/src/libutil/types.hh @@ -1,15 +1,12 @@ #pragma once - -#include "ref.hh" - -#include <string> +#include <boost/format.hpp> #include <list> -#include <set> -#include <memory> #include <map> - -#include <boost/format.hpp> +#include <memory> +#include <set> +#include <string> +#include "ref.hh" /* Before 4.7, gcc's std::exception uses empty throw() specifiers for * its (virtual) destructor and what() in c++11 mode, in violation of spec @@ -20,131 +17,103 @@ #endif #endif - namespace nix { - /* Inherit some names from other namespaces for convenience. */ -using std::string; +using boost::format; using std::list; using std::set; +using std::string; using std::vector; -using boost::format; - /* A variadic template that does nothing. Useful to call a function for all variadic arguments but ignoring the result. */ -struct nop { template<typename... T> nop(T...) {} }; - - -struct FormatOrString -{ - string s; - FormatOrString(const string & s) : s(s) { }; - FormatOrString(const format & f) : s(f.str()) { }; - FormatOrString(const char * s) : s(s) { }; +struct nop { + template <typename... T> + nop(T...) {} }; +struct FormatOrString { + string s; + FormatOrString(const string& s) : s(s){}; + FormatOrString(const format& f) : s(f.str()){}; + FormatOrString(const char* s) : s(s){}; +}; /* A helper for formatting strings. ‘fmt(format, a_0, ..., a_n)’ is equivalent to ‘boost::format(format) % a_0 % ... % ... a_n’. However, ‘fmt(s)’ is equivalent to ‘s’ (so no %-expansion takes place). */ -inline std::string fmt(const std::string & s) -{ - return s; -} +inline std::string fmt(const std::string& s) { return s; } -inline std::string fmt(const char * s) -{ - return s; -} +inline std::string fmt(const char* s) { return s; } -inline std::string fmt(const FormatOrString & fs) -{ - return fs.s; -} +inline std::string fmt(const FormatOrString& fs) { return fs.s; } -template<typename... Args> -inline std::string fmt(const std::string & fs, Args... args) -{ - boost::format f(fs); - f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); - nop{boost::io::detail::feed(f, args)...}; - return f.str(); +template <typename... Args> +inline std::string fmt(const std::string& fs, Args... args) { + boost::format f(fs); + f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); + nop{boost::io::detail::feed(f, args)...}; + return f.str(); } - /* BaseError should generally not be caught, as it has Interrupted as a subclass. Catch Error instead. */ -class BaseError : public std::exception -{ -protected: - string prefix_; // used for location traces etc. - string err; -public: - unsigned int status = 1; // exit status - - template<typename... Args> - BaseError(unsigned int status, Args... args) - : err(fmt(args...)) - , status(status) - { - } - - template<typename... Args> - BaseError(Args... args) - : err(fmt(args...)) - { - } +class BaseError : public std::exception { + protected: + string prefix_; // used for location traces etc. + string err; + + public: + unsigned int status = 1; // exit status + + template <typename... Args> + BaseError(unsigned int status, Args... args) + : err(fmt(args...)), status(status) {} + + template <typename... Args> + BaseError(Args... args) : err(fmt(args...)) {} #ifdef EXCEPTION_NEEDS_THROW_SPEC - ~BaseError() throw () { }; - const char * what() const throw () { return err.c_str(); } + ~BaseError() throw(){}; + const char* what() const throw() { return err.c_str(); } #else - const char * what() const noexcept { return err.c_str(); } + const char* what() const noexcept { return err.c_str(); } #endif - const string & msg() const { return err; } - const string & prefix() const { return prefix_; } - BaseError & addPrefix(const FormatOrString & fs); + const string& msg() const { return err; } + const string& prefix() const { return prefix_; } + BaseError& addPrefix(const FormatOrString& fs); }; #define MakeError(newClass, superClass) \ - class newClass : public superClass \ - { \ - public: \ - using superClass::superClass; \ - }; + class newClass : public superClass { \ + public: \ + using superClass::superClass; \ + }; MakeError(Error, BaseError) -class SysError : public Error -{ -public: - int errNo; - - template<typename... Args> - SysError(Args... args) - : Error(addErrno(fmt(args...))) - { } + class SysError : public Error { + public: + int errNo; -private: + template <typename... Args> + SysError(Args... args) : Error(addErrno(fmt(args...))) {} - std::string addErrno(const std::string & s); + private: + std::string addErrno(const std::string& s); }; - typedef list<string> Strings; typedef set<string> StringSet; typedef std::map<std::string, std::string> StringMap; - /* Paths are just strings. */ typedef string Path; typedef list<Path> Paths; typedef set<Path> PathSet; - -} +} // namespace nix |