How to import for mixin contents only.

Taylor Hillegeist via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 10 08:20:42 PST 2016


On Thursday, 10 March 2016 at 04:56:52 UTC, Mike Parker wrote:
> On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist 
> wrote:
>> So i want bitfields for just a little bit. but i dont want its 
>> dependencies. How is it done. I have tried this. but it doesnt 
>> seem to work on gdc. :(
>>
>> struct Color_t {
>> 	static if(__ctfe){
>> 		import std.bitmanip:bitfields;
>> 	}
>> 	mixin(bitfields!(
>> 		uint, "R",    8,
>> 		uint, "G",   8,
>> 		uint, "B",    8,
>> 		uint, "A", 8));
>> }
>
> __ctfe is a runtime construct, not compile-time. It cannot be 
> used with static if. More over, it's only available *inside* a 
> function that is currently being executed in a compile-time 
> context. It has no role outside of that.
>
> What problem are you trying to solve here? I mean, what is the 
> problem with whatever dependencies std.bitmanip:bitfields has 
> that makes you only want to import it during compilation?

I feel like this should do what i want it too. but it doesn't.

struct Color_t {
	static if(1==1){
		import std.bitmanip:bitfields;
		immutable string item = bitfields!(		
				uint, "R",    8,
				uint, "G",   8,
				uint, "B",    8,
				uint, "A", 8);
	}
	mixin(item);
}


More information about the Digitalmars-d-learn mailing list