Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TaskLocal disable emplacing init value #825

Closed
rikkimax opened this issue Sep 13, 2014 · 2 comments
Closed

TaskLocal disable emplacing init value #825

rikkimax opened this issue Sep 13, 2014 · 2 comments

Comments

@rikkimax
Copy link

Long story short I need to prevent TaskLocal from emplacing with its default (given) value.

My solution is basically:

struct TaskLocal(T, bool initWithData=true)

And in storage method:
https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/core.d#L857

static if (initWithData) {
    emplace!T(data, m_initValue);
} else {
    emplace!T(data);
}

I'm sure there is a better way to do this.

@s-ludwig
Copy link
Member

What about adding a field m_hasInitValue that will be set to true only if the appropriate constructor is called, and use that to determine which version of emplace to use?

Just out of interest, why does this case issues for you? Is emplace erroneously trying to call a constructor instead of directly initializing with m_initValue?

@rikkimax
Copy link
Author

Right sorry for late reply chrome didn't update grr.
Basically emplace tries to execute a constructor when it requires things it cannot use.

Context: LuaState (luad) as a global variable that is per not so much connection but the thread it is running upon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants