argparse version 0.7.0 - a CLI parsing library
    H. S. Teoh 
    hsteoh at quickfur.ath.cx
       
    Fri Mar 18 21:49:28 UTC 2022
    
    
  
On Fri, Mar 18, 2022 at 09:30:57PM +0000, Adam Ruppe via Digitalmars-d-announce wrote:
[...]
> One approach you might consider is a hybrid too, where you have the
> big struct you build out of the individual udas.
> 
> So you work on the big one but you do getBig!decl and it loops through
> the members of thebig struct and sees if the same-typed UDAs are on
> decl. If so, it loads them in, if not, it leaves default values.
[...]
Yeah, that's what I thought too. So you could have something like this:
	struct SmallUDA {}
	struct AnotherSmallUDA {}
	struct AggregateUDAs {
		bool hasSmall;
		bool hasAnotherSmall;
		static typeof(this) opCall(T)() {
			AggregateUDAs result;
			hasSmall = hasUDA!(T, SmallUDA);
			hasAnotherSmall = hasUDA!(T, AnotherSmallUDA);
			return result;
		}
	}
	void processUDAs(T)() {
		// Look ma! No need to sprinkle hasUDA everywhere
		enum aggreg = AggregateUDAs!T();
		...
		static if (aggreg.hasSmall) { ... }
		...
		static if (aggreg.hasAnotherSmall) { ... }
		...
	}
	@SmallUDA
	@AnotherSmallUDA
	struct MyInputType { ... }
	processUDAs!MyInputType();
T
-- 
Why did the mathematician reinvent the square wheel?  Because he wanted to drive smoothly over an inverted catenary road.
    
    
More information about the Digitalmars-d-announce
mailing list