I tried to make a static claim on the template parameter to check / apply type
Although the static claim fails to be reproducible, I do not understand why, and no document can be found, why it will fail on static evaluation.
The institutionalized class is copyable, though it is used by those people, which I believe is curiously called recurring template parameter patterns.
The full test code below is:
# include & lt; Iostream & gt; # Include & lt; Type_traits & gt; using namespace std; Template & lt; Typename type & gt; Class FunContainer {// static_assert (is_copy_constructible & lt; type & gt; :: value, "the type must be copyable!"); // & lt; - It fails // bool copyable = is_copy_constructible & lt; Type & gt; :: value // & lt; - The second effect will be secure: int container_stuff = 0; Public: int get_container_stuff () {return container_stuff;}; Zero set_container_stuff (intel stuff) {container_stuff = stuff;}; Bool is_copyable () {return is_copy_constructible & lt; Type & gt; :: value;}; }; Class Fun: Public FunContainer & lt; Fun & gt; {Public: std :: string str = "tastic"; Have fun () = default; Fun (Constant Fun and Other_fan): Fun Container & lt; Fun & gt; (Other_fan) {copy_internals (other_fun); }; Fun & amp; Operator = (console fun and other_fan) {Fun Container & lt; Fun & gt; :: operator = (other_fan); Copy_internals (other_fun); Return * This; }; Private: Zero copy_internals (const fun and other_fun) {str = other_fun.str;}; }; Static_assert (is_copy_constructible & lt; Fun & gt; :: Value, "the type should be copied!"); // & lt; - second emphasis int main () {fun fun; Fun.set_container_stuff (10); Fun.str = "test"; Fun Task (fun); Cout & lt; & Lt; Tastic.get_container_stuff () & lt; & Lt; '\ N'; Cout & lt; & Lt; Tastic.str & lt; & Lt; '\ N'; Cout & lt; & Lt; Tastic.is_copyable () & lt; & Lt; '\ N'; Return 0; }
The result is expected:
10 test1
This means that the second emphasis is given So it seems that fun
is not inside CopyConstructible FunContainer
. However, is_copyable
says that it is.
I tried to use the is_copyable ()
method in the initial class, this second claim is unsuccessful. When disrupting the accused, the value is removed; copyable
is set to 0;
It seems that the only evaluation is static copmile-time within the base class.
Q1 Why compile-time check is false
and "run-time" is true
? Does this fail because the class ( fun
) is not completely immediately defined / deferred?
Q2 Is it expected? (It is that static evaluation of is_copy_constructible results from different "run-time" one).
Q3 Is there a way to claim a compile time, is it copied with this kind of design?
Tested on chime 3.2-11, GCC 4.8.2 and Ideaan default C ++ 11 compiler.
Q1 why the compile-time check is incorrect and " Run-time "right? Does it fail because class (fun) is not fully defined at initial / check time?
Yes FunContainer & lt; Fun & gt;
, when you use it as the base class of funny
is defined before fun
.
Q2 Is it expected?
Yes.
Q3 Is there any way to claim a compile time to check that the class is copied with the same design?
Take your static claim somewhere that goes immediately afterwards. The creator of the Fun Container
looks like a good choice for me.
Comments
Post a Comment