Skip to content

Commit

Permalink
macroify the proxied functions
Browse files Browse the repository at this point in the history
  • Loading branch information
akrieger committed Dec 26, 2023
1 parent 3d5a0eb commit ec501ee
Showing 1 changed file with 27 additions and 54 deletions.
81 changes: 27 additions & 54 deletions src/value_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ struct heap {
public:

// Various conditionally defined proxy functions for common types like containers.
#pragma push_macro("PROXY")
#define PROXY(func) \
template<typename ...Us> \
auto func( Us&& ...us ) -> decltype( val().func( std::forward<Us>( us )... ) ) { \
return val().func( std::forward<Us>( us )... ); \
}
#pragma push_macro("PROXY_CONST")
#define PROXY_CONST(func) \
template<typename ...Us> \
auto func( Us&& ...us ) const -> decltype( val().func( std::forward<Us>( us )... ) ) { \
return val().func( std::forward<Us>( us )... ); \
}

// Comparison operators.
auto operator==( heap const &rhs ) const -> decltype( val() == val() ) {
Expand All @@ -165,70 +177,29 @@ struct heap {


// Tests & sets
auto empty() const -> decltype( val().empty() ) {
return val().empty();
}

template<typename U>
auto count( U &&u ) const -> decltype( val().count( std::forward<U>( u ) ) ) {
return val().count( std::forward<U>( u ) );
}

auto size() const -> decltype( val().size() ) {
return val().size();
}

auto clear() -> decltype( val().clear() ) {
return val().clear();
}
PROXY_CONST( empty )
PROXY_CONST( count )
PROXY_CONST( size )
PROXY( clear )

// Iterators
auto begin() -> decltype( val().begin() ) {
return val().begin();
}

auto begin() const -> decltype( val().begin() ) {
return val().begin();
}

auto end() -> decltype( val().end() ) {
return val().end();
}

auto end() const -> decltype( val().end() ) {
return val().end();
}
PROXY( begin )
PROXY_CONST( begin )
PROXY( end )
PROXY_CONST( end )

// Accessors
template<typename U>
auto operator[]( U &&u ) -> decltype( val()[std::forward<U>( u )] ) {
return val()[std::forward<U>( u )];
}

template<typename U>
auto find( U &&u ) -> decltype( val().find( std::forward<U>( u ) ) ) {
return val().find( std::forward<U>( u ) );
}

template<typename U>
auto find( U &&u ) const -> decltype( val().find( std::forward<U>( u ) ) ) {
return val().find( std::forward<U>( u ) );
}

template<typename U>
auto erase( U &&u ) -> decltype( val().erase( std::forward<U>( u ) ) ) {
return val().erase( std::forward<U>( u ) );
}
PROXY( find )
PROXY_CONST( find )

template<typename U>
auto insert( U &&u ) -> decltype( val().insert( std::forward<U>( u ) ) ) {
return val().insert( std::forward<U>( u ) );
}

template<typename U>
auto emplace( U &&u ) -> decltype( val().emplace( std::forward<U>( u ) ) ) {
return val().emplace( std::forward<U>( u ) );
}
PROXY( erase )
PROXY( insert )
PROXY( emplace )

// Json* support.
template<typename Stream = JsonOut>
Expand All @@ -240,6 +211,8 @@ struct heap {
void deserialize( const Value &jsin ) {
jsin.read( val() );
}
#pragma pop_macro("PROXY")
#pragma pop_macro("PROXY_CONST")
};

} // namespace cata
Expand Down

0 comments on commit ec501ee

Please sign in to comment.