diff --git a/spec/traits.dd b/spec/traits.dd index 19e6e9557c..a39b0eaa3d 100644 --- a/spec/traits.dd +++ b/spec/traits.dd @@ -63,6 +63,7 @@ $(GNAME TraitsKeyword): $(RELATIVE_LINK2 getOverloads, $(D getOverloads)) $(RELATIVE_LINK2 getParameterStorageClasses, $(D getParameterStorageClasses)) $(RELATIVE_LINK2 getPointerBitmap, $(D getPointerBitmap)) + $(RELATIVE_LINK2 getCppNamespaces, $(D getCmdlineConstant)) $(RELATIVE_LINK2 getCppNamespaces, $(D getCppNamespaces)) $(RELATIVE_LINK2 getVisibility, $(D getVisibility)) $(RELATIVE_LINK2 getProtection, $(D getProtection)) @@ -1417,6 +1418,31 @@ bar(T)() bar(int n) ) +$(H3 $(GNAME getCmdlineConstant)) + $(P The first argument is a string representing the name of the constant, the optional second argument + is a type or false, the optional third argument is an expression and is used as default in case the constant + has not been passed to the compiler. + + The name of the constant must contain the name of the fully qualified module, otherwise it will be added implicitly + + If the second argument contains a type then the constant value will be returned after evaluation if the type of + the expression defined in the constant is equal to or implicitly convertible with the type passed to the second argument + If the second argument is not present or false then the value of the constant will be returned as a string without any evaluation + ) + +$(SPEC_RUNNABLE_EXAMPLE_COMPILE +--- +# compiler defined constans: mymod.test1=some_text, mymod.test2=4 + +module mymod; +pragma(msg, __traits(getCmdlineConstant, "test1")); // Prints "some_text" +pragma(msg, __traits(getCmdlineConstant, "mymod.test1")); // Prints "some_text" +pragma(msg, __traits(getCmdlineConstant, "test2", false)); // Prints string "4" +pragma(msg, __traits(getCmdlineConstant, "test2", int)); // Prints integer 4 +pragma(msg, __traits(getCmdlineConstant, "test3", int, 2)); // Constant not passed to dmd --> fallback default -> Prints integer 2 +--- +) + $(H3 $(GNAME getCppNamespaces)) $(P The argument is a symbol. The result is a *ValueSeq* of strings, possibly empty, that correspond to the namespaces the symbol resides in.