Variable findFirstUDA

Small convenience wrapper to find and extract certain UDA from given type. Will stop on first element which is of required type.

Declaration

module vibe.internal.meta.uda;

// ...
void findFirstUDA(UDA, alias Symbol, bool allow_types);
// ...

Parameters

NameDescription
UDA type to search for in UDA list
Symbol symbol to query for UDA's
allow_types if set to `false` considers attached `UDA` types an error (only accepts instances/values)

Returns

aggregated search result struct with 3 field. `value` aliases found UDA. `found` is boolean flag for having a valid find. `index` is integer index in attribute list this UDA was found at.

Example

struct Attribute { int x; }

@("something", Attribute(42), Attribute(41))
	void symbol();

enum result0 = findFirstUDA!(string, symbol);
	static assert (result0.found);
	static assert (result0.index == 0);
	static assert (result0.value == "something");

	enum result1 = findFirstUDA!(Attribute, symbol);
	static assert (result1.found);
	static assert (result1.index == 1);
	static assert (result1.value == Attribute(42));

	enum result2 = findFirstUDA!(int, symbol);
static assert (!result2.found);

Authors

Sönke Ludwig, Михаил Страшун

Copyright

© 2013 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.