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

Comments

Projects
None yet
2 participants
@rikkimax

rikkimax commented Sep 13, 2014

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

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Sep 13, 2014

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?

Member

s-ludwig commented Sep 13, 2014

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

This comment has been minimized.

Show comment
Hide comment
@rikkimax

rikkimax Sep 16, 2014

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.

rikkimax commented Sep 16, 2014

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.

@s-ludwig s-ludwig closed this in 3849f04 Sep 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment