flows.insert({currentNamespace, {flow}}); Why cant I emplace, flows is of type…
- User
flows.insert({currentNamespace, {flow}});
Why cant I emplace, flows is of type std::unordered_map<std::string, std::vector>;
- Assistant
The
std::unordered_map::emplacefunction is typically used to construct elements in-place, which can be more efficient by avoiding unnecessary copies. However, when usingemplacewith a map where the value type is a container likestd::vector, you might encounter issues if the arguments don't match any constructor for the value type (std::vector<Flow>in this case).Let's go through the situation you described:
-
insertUsage:
-
- User
How can I have a default parameter in a c++ macro ?
- Assistant
C++ macros, defined using the
#definedirective, are a preprocessor feature and do not inherently support default parameters in the same way that functions do (because they are not functions but rather simple text substitutions). However, you can simulate default parameters using a trick with variadic macros.Here's how you can achieve something similar to default parameters with macros:
-
Variadic Macros: These allow you to define a macro that can accept a variable number of arguments.
-
- User
#define GET_MACRO(_1, _2, NAME, ...) NAME #define FUNC_DEFAULT(ReturnType, Name, Pattern) inline static ReturnType Name = mem::scan(mem::pattern(Pattern), OS_REGION) #define FUNC_NO_DEFAULT(arg1, arg2) FUNC_DEFAULT(arg1, arg2, mem::pointer)
// The main macro that chooses which implementation to use #define PATTERN(...) GET_MACRO(VA_ARGS, FUNC_DEFAULT, FUNC_NO_DEFAULT)(VA_ARGS)
- Assistant
- User
This is valid ?
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define FUNC_DEFAULT(Name, Pattern, ReturnType) inline static ReturnType Name = mem::scan(mem::pattern(Pattern), OS_REGION) #define FUNC_NO_DEFAULT(Name, Pattern) FUNC_DEFAULT(Name, Pattern, mem::pointer)
// The main macro that chooses which implementation to use #define PATTERN(...) GET_MACRO(VA_ARGS, FUNC_DEFAULT, FUNC_NO_DEFAULT)(VA_ARGS)
namespace patterns::CVehicleFactory { PATTERN(Instance, "48 8B 1D ? ? ? ? 48 8D 8C 24").add(3); }
- Assistant