Skip to content

Commit

Permalink
Explicit value_type for ConfigOptionProxy (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegan authored Jan 31, 2024
1 parent c6c9275 commit ea905cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/util/ConfigManager/ConfigOptionProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class ConfigOptionProxyImplementation {
ConfigOptionType* option_;

public:
using Type = T;

// Custom constructor.
explicit ConfigOptionProxyImplementation(ConfigOptionType& opt)
: option_(&opt) {
Expand Down Expand Up @@ -81,6 +79,9 @@ class ConstConfigOptionProxy
ConfigManagerImpl::ConfigOptionProxyImplementation<T, const ConfigOption>;

public:
using value_type = T;

// Construct proxy for the given option.
explicit ConstConfigOptionProxy(const ConfigOption& opt) : Base(opt) {}
};

Expand All @@ -94,6 +95,9 @@ class ConfigOptionProxy
ConfigManagerImpl::ConfigOptionProxyImplementation<T, ConfigOption>;

public:
using value_type = T;

// Construct proxy for the given option.
explicit ConfigOptionProxy(ConfigOption& opt) : Base(opt) {}

// Implicit conversion from not const to const is allowed.
Expand Down
7 changes: 4 additions & 3 deletions test/ConfigOptionProxyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../test/util/GTestHelpers.h"
#include "util/ConfigManager/ConfigOption.h"
#include "util/ConfigManager/ConfigOptionProxy.h"
#include "util/TypeTraits.h"

namespace ad_utility {

Expand All @@ -21,16 +22,16 @@ namespace ad_utility {
@tparam OptionType Exists to define, if the test should be done with
`ConfigOption`, or `const ConfigOption`.
*/
template <template <typename> typename ProxyType, typename OptionType>
requires std::same_as<OptionType, ConfigOption> ||
std::same_as<OptionType, const ConfigOption>
template <template <typename> typename ProxyType,
SameAsAny<ConfigOption, const ConfigOption> OptionType>
void basicConstructorTest() {
// Test construction for a given type.
auto doTest = []<typename T>() {
// Does the normal constructor work?
T varForConfigOption;
OptionType opt("testOption", "", &varForConfigOption);
ASSERT_EQ(&opt, &ProxyType<T>(opt).getConfigOption());
static_assert(std::same_as<T, typename ProxyType<T>::value_type>);

// Is there an exception, if we give a config option of the wrong type?
doForTypeInConfigOptionValueType([&opt]<typename WrongT>() {
Expand Down

0 comments on commit ea905cc

Please sign in to comment.