Converting between function and methods
Using BRONTO_INLINE()
to convert a free function a method
You can use BRONTO_INLINE()
to convert a free function into a method.
First implement your free function in terms of the member function you want to call.
bool StartsWith(std::string_view s, std::string_view prefix) {
return s.starts_with(prefix);
}
Now annotate the old function to be inlined.
BRONTO_INLINE()
bool StartsWith(std::string_view s, std::string_view prefix) {
return s.starts_with(prefix);
}
Sit back while Bronto switches all the callers to the member function.
After Bronto has migrated all calls to StartsWith
, you can simply delete it.
See it in action on Compiler Explorer.
Using BRONTO_INLINE()
to convert a method to a free function
You can use BRONTO_INLINE()
to convert a method to a free function as well.
First implement your method in terms of the free function you want to replace it with.
struct Pet;
void FeedPet(const Pet& p, int food_type);
struct Pet {
void Feed() const {
FeedPet(*this, PreferedFood());
}
int PreferedFood() const;
};
Now annotate the old function to be inlined.
struct Pet;
void FeedPet(const Pet& p, int food_type);
struct Pet {
BRONTO_INLINE()
void Feed() const {
FeedPet(*this, PreferedFood());
}
int PreferedFood() const;
};
Sit back while Bronto switches all the callers to the free function.
After Bronto has migrated all calls to FeedPet
, you can simply delete
Pet::Feed
.
See it in action on Compiler Explorer.