X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/c00e81f9f50c4fe50ee32b02a689d68c9bc595b6..4ec483cf24cf5474cdcacf355132070a3661c186:/projects/sgconf/utils.h diff --git a/projects/sgconf/utils.h b/projects/sgconf/utils.h index 2e16b625..3a57d999 100644 --- a/projects/sgconf/utils.h +++ b/projects/sgconf/utils.h @@ -1,48 +1,45 @@ -#ifndef __STG_SGCONF_UTILS_H__ -#define __STG_SGCONF_UTILS_H__ +#pragma once #include "stg/common.h" -#include "stg/resetable.h" #include #include +#include namespace SGCONF { template inline -void MaybeSet(const std::map & options, const std::string & name, RESETABLE & res) +void MaybeSet(const std::map & options, const std::string & name, std::optional & res) { -std::map::const_iterator it(options.find(name)); -if (it == options.end()) - return; -T value; -if (str2x(it->second, value) < 0) - return; -res = value; + std::map::const_iterator it(options.find(name)); + if (it == options.end()) + return; + T value; + if (str2x(it->second, value) < 0) + return; + res = value; } template inline -void MaybeSet(const std::map & options, const std::string & name, RESETABLE & res, F conv) +void MaybeSet(const std::map & options, const std::string & name, T & res, F conv) { -std::map::const_iterator it(options.find(name)); -if (it == options.end()) - return; -conv(it->second, res); + std::map::const_iterator it(options.find(name)); + if (it == options.end()) + return; + conv(it->second, res); } template <> inline -void MaybeSet(const std::map & options, const std::string & name, RESETABLE & res) +void MaybeSet(const std::map & options, const std::string & name, std::optional & res) { -std::map::const_iterator it(options.find(name)); -if (it == options.end()) - return; -res = it->second; + std::map::const_iterator it(options.find(name)); + if (it == options.end()) + return; + res = it->second; } } // namespace SGCONF - -#endif