Utilities for creating a struct with a subset of fields of the original struct, with conversions between them.
Definition in file struct_subsets.hpp.
Go to the source code of this file.
#include <type_traits>
#include <utility>
#include <boost/preprocessor/empty.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <userver/utils/impl/boost_variadic_to_seq.hpp>
#include <userver/utils/impl/internal_tag.hpp>
Namespaces | |
namespace | utils |
Utilities. | |
Macros | |
#define | USERVER_ALLOW_CONVERSIONS_TO_SUBSET() |
Should be invoked inside a manually defined "root" struct to enable conversions from it to subset structs created by USERVER_MAKE_STRUCT_SUBSET and USERVER_MAKE_STRUCT_SUBSET_REF. | |
#define | USERVER_DEFINE_STRUCT_SUBSET(SubsetStruct, OriginalStruct, ...) |
Defines a struct containing a subset of data members from OriginalDependencies. | |
#define | USERVER_DEFINE_STRUCT_SUBSET_REF(SubsetStructRef, OriginalStruct, ...) |
Defines a struct containing a subset of data members from OriginalDependencies. Appends const& to types of all non-reference data members. | |
#define USERVER_ALLOW_CONVERSIONS_TO_SUBSET | ( | ) |
Should be invoked inside a manually defined "root" struct to enable conversions from it to subset structs created by USERVER_MAKE_STRUCT_SUBSET and USERVER_MAKE_STRUCT_SUBSET_REF.
Definition at line 74 of file struct_subsets.hpp.
#define USERVER_DEFINE_STRUCT_SUBSET | ( | SubsetStruct, | |
OriginalStruct, | |||
... ) |
Defines a struct containing a subset of data members from OriginalDependencies.
Implicit conversions (by copy and by move) are allowed from any superset struct to the SubsetStruct, as long as the names of the data members match, and the superset struct is either defined using USERVER_MAKE_STRUCT_SUBSET or USERVER_MAKE_STRUCT_SUBSET_REF, or it contains USERVER_ALLOW_CONVERSIONS_TO_SUBSET.
Usage example:
SubsetStruct | the name of the subset struct to define |
OriginalStruct | the name of the superset struct, including its namespace if needed |
... | names of the data members to copy |
Definition at line 117 of file struct_subsets.hpp.
#define USERVER_DEFINE_STRUCT_SUBSET_REF | ( | SubsetStructRef, | |
OriginalStruct, | |||
... ) |
Defines a struct containing a subset of data members from OriginalDependencies. Appends const&
to types of all non-reference data members.
Implicit conversions (by copy and by move) are allowed from any superset struct to the SubsetStruct, as long as the names of the data members match, and the superset struct is either defined using USERVER_MAKE_STRUCT_SUBSET or USERVER_MAKE_STRUCT_SUBSET_REF, or it contains USERVER_ALLOW_CONVERSIONS_TO_SUBSET.
*Ref
structs can be used for parameters of utility functions to avoid copying non-reference data members.
Usage example:
SubsetStructRef | the name of the subset struct to define, it should typically contain *Ref suffix to underline that it needs the original backing struct to work |
OriginalStruct | the name of the superset struct, including its namespace if needed |
... | names of the data members to copy |
Definition at line 153 of file struct_subsets.hpp.