digitalmars.D.learn - How to capture a BitFlags type in a function parameter?
- realhet (14/14) Jan 31 2021 Hi,
- Paul Backus (8/18) Jan 31 2021 Your problem is that you are trying to match `U`, a template type
- realhet (4/9) Jan 31 2021 Thank You!
Hi, I wan't to process every specialization of the BitFlags struct in a function: So far the best I can come up is this: static void stdUI(F)(ref F flags) if(F.stringof.startsWith("BitFlags!(")){} But it's obviously lame. If I try this way: static void stdUI(E, U)(ref BitFlags!(E, U) flags){} I get a cannot deduce arguments error. Same error with: static void stdUI(E, U, B = BitFlags!(E, U))(ref B flags){} I'd like to know the Enum type as well. Thank You for your help in advance!
Jan 31 2021
On Sunday, 31 January 2021 at 14:04:00 UTC, realhet wrote:Hi, I wan't to process every specialization of the BitFlags struct in a function: So far the best I can come up is this: static void stdUI(F)(ref F flags) if(F.stringof.startsWith("BitFlags!(")){} But it's obviously lame. If I try this way: static void stdUI(E, U)(ref BitFlags!(E, U) flags){} I get a cannot deduce arguments error.Your problem is that you are trying to match `U`, a template type parameter [1], with BitFlags' `unsafe`, a template value parameter [2]. It should work if you change it to: static void stdUI(E, Flag!"unsafe" u)(ref BitFlags!(E, u) flags) {} [1] https://dlang.org/spec/template.html#template_type_parameters [2] https://dlang.org/spec/template.html#template_value_parameter
Jan 31 2021
On Sunday, 31 January 2021 at 14:16:15 UTC, Paul Backus wrote:On Sunday, 31 January 2021 at 14:04:00 UTC, realhet wrote:Thank You! Somehow I forgot I could pass amd match ANY TYPE in the template parameters. I'll remember this, thanks!Hi,static void stdUI(E, Flag!"unsafe" u)(ref BitFlags!(E, u) flags) {}
Jan 31 2021