-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generic_factory: support relative & proportional (#43144)
In the hope of eventually removing the assign() functions, and expanding support for generic factory (and continuing to support existing use cases), generic_factory needs to support relative and proportional. To do this, do some template vodoo. Create two templated structs, and take advantage of SFINAE (yeah, I had to look that up) with these to determine which template function to use. Three basically discriminate between whether or not the type can specify value proportionally or relatively. For proportionally, this is whether or not the type can be multiplied by a float, and for relative, this is whether or not the type can use the += operator with itself. Also, add some error checking for when a proportional value is inappropriately specified. Containers using the reader functions do not have proportional and relative support, because I'm not sure of a use case where that ever makes sense. Huge thanks to jbytheway for helping me use template vodoo to accomplish this.
- Loading branch information
1 parent
ee1873d
commit add6f7d
Showing
2 changed files
with
237 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef CATA_SRC_CATA_VOID_H | ||
#define CATA_SRC_CATA_VOID_H | ||
|
||
// For some template magic in generic_factory.h, it's much easier to use void_t | ||
// However, C++14 does not have this, so we need our own. | ||
// It's nothing complex, just strip it out when C++17 comes. | ||
namespace cata | ||
{ | ||
template<typename...> | ||
using void_t = void; | ||
} // namespace cata | ||
|
||
#endif // CATA_SRC_CATA_VOID_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters