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

Issue 16168 - isCopyable trait for value types #4706

Merged
merged 1 commit into from
Aug 30, 2016
Merged

Issue 16168 - isCopyable trait for value types #4706

merged 1 commit into from
Aug 30, 2016

Conversation

BradleyChatha
Copy link
Contributor

This is the first time I've contributed code to a project(other than a slight documentation improvement), so I'm sorry if I've messed up something.

https://issues.dlang.org/show_bug.cgi?id=16168

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
16168 isCopyable trait for value types

@wilzbach
Copy link
Member

wilzbach commented Aug 3, 2016

This is the first time I've contributed code to a project(other than a slight documentation improvement)

That's great to hear!

so I'm sorry if I've messed up something.

Do you see the failing CI integrations?
If you click on them you see why they are failing. It looks like it's just a style issue ;-)

+ `true` if `S` can be copied.
+ ++/
template isCopyable(S)
if(!is(S == class))
Copy link
Member

@MetaLang MetaLang Aug 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also check whether S is an interface using !is(S == interface). Please also a test to check whether a class and an interface are copyable.

@andralex
Copy link
Member

preapproved pending changes

@BradleyChatha
Copy link
Contributor Author

I'm not sure if it's worth mentioning, but using S foo; S bar = foo; causes isCopyable to be false when using isCopyable!S2 in the unittest. But using S foo = S.init; S bar = foo; makes it true.

Example:
https://dpaste.dzfl.pl/10aa9f47979d

@japplegame
Copy link
Contributor

isCopyable needs frame pointer, because S2 is nested. Just add static before struct definition and tests will pass.
Anyway you should not use S foo; or S foo = S.init; because the default constructor can be disabled and S.init can be overridden. Use S foo = void; instead.
Personally, I prefer

enum isCopyConstructible(T, From = T) = is(typeof({ From from = void; T t = from; }));

@andralex andralex merged commit cb09746 into dlang:master Aug 30, 2016
@BradleyChatha BradleyChatha deleted the issue_16168 branch September 3, 2016 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants