f



Preconditions and semantics of std::is_constructible and std::is_assignable in N3242 (C++0x draft)

1) Preconditions for std::is_constructible<T, Args...> are specified
as follows:

     T and all types in the parameter pack Args shall be complete
types, (possibly cv-qualified) void, or arrays of unknown bound.

If my understanding is correct, X const & is complete type regardless
of whether X is complete type, so the following program is well-
defined and shall print zero:

-------------------------------------------------
#include <iostream>
#include <type_traits>

struct X;

int main()
{
     std::cout << (int)std::is_constructible<X const &, int>::value;
}

struct X
{
     X(int) {}
};
-------------------------------------------------

Am I right?

2) Preconditions for std::is_assignable<T, U> are specified as
follows:

     T and U shall be complete types, (possibly cv-qualified) void, or
arrays of unknown bound.

In the following example X & and X const & are complete types
regardless of whether X is complete type:

-------------------------------------------------
#include <iostream>
#include <type_traits>

struct X;

int main()
{
     std::cout << (int)std::is_assignable<X &, X const &>::value;
}

struct X {};
-------------------------------------------------

Should this program be well-defined and print zero?


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Nikolay
3/3/2011 6:09:48 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

3 Replies
554 Views

Similar Articles

[PageSpeed] 15

On 2011-03-03 13:09, Nikolay Ivchenkov wrote:
>
> 1) Preconditions for std::is_constructible<T, Args...>  are specified
> as follows:
>
>       T and all types in the parameter pack Args shall be complete
> types, (possibly cv-qualified) void, or arrays of unknown bound.
>
> If my understanding is correct, X const&  is complete type regardless
> of whether X is complete type, so the following program is well-
> defined and shall print zero:
>
> -------------------------------------------------
> #include<iostream>
> #include<type_traits>
>
> struct X;
>
> int main()
> {
>       std::cout<<  (int)std::is_constructible<X const&, int>::value;
> }
>
> struct X
> {
>       X(int) {}
> };
> -------------------------------------------------
>
> Am I right?

I agree with your interpretation, but the intention is different. The
intention is that this *should* be a violation of pre-conditions.
Unfortunately the pre-conditions are not all correct.

> 2) Preconditions for std::is_assignable<T, U>  are specified as
> follows:
>
>       T and U shall be complete types, (possibly cv-qualified) void, or
> arrays of unknown bound.
>
> In the following example X&  and X const&  are complete types
> regardless of whether X is complete type:
>
> -------------------------------------------------
> #include<iostream>
> #include<type_traits>
>
> struct X;
>
> int main()
> {
>       std::cout<<  (int)std::is_assignable<X&, X const&>::value;
> }
>
> struct X {};
> -------------------------------------------------
>
> Should this program be well-defined and print zero?

Same thing here. This program is not intended to be well-defined.

The hard part is too define the pre-conditions in a way such that normal
users don't get annoyed about too strict limitations. For example there
should be no problem for code like this

#include<iostream>
#include<type_traits>

struct X;

int main()
{
       std::cout<<  (int)std::is_constructible<X const&, X>::value;
       std::cout<<  (int)std::is_constructible<X&, X&>::value;
       std::cout<<  (int)std::is_constructible<X&&, X>::value;
}

struct X
{
};

because all these operations are just bindings of references to possibly
cv-qualified versions of the same type.

As an approach to attack this problem we can probably discriminate the
following situations:

is_**_destructible: The current pre-conditions look ok
is_**_assignable: At least std::remove_reference<destination type>::type
needs to be a complete type. This would solve the problem in your first
example. We could be stricter and require that also
std::remove_reference<source type>::type is complete. This would fix
situations where a conversion function from source could be involved,
but it would forbid us to use std::is_assignable for situations like these:

struct Ukn;

struct S {
   S& operator=(Ukn&);
};

int i = std::is_assignable<S, Ukn&>::value;

So what are the ideal pre-conditions for providing useful user-support
but not imposing?

Greetings from Bremen,

Daniel Kr�gler





-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
ISO
3/7/2011 11:11:10 AM
On 7 Mar, 20:11, Daniel Kru"gler <daniel.krueg...@googlemail.com>
wrote:
> On 2011-03-03 13:09, Nikolay Ivchenkov wrote:
>
> > 1) Preconditions for std::is_constructible<T, Args...>  are specified
> > as follows:
>
> >       T and all types in the parameter pack Args shall be complete
> > types, (possibly cv-qualified) void, or arrays of unknown bound.
>
> > If my understanding is correct, X const&  is complete type regardless
> > of whether X is complete type, so the following program is well-
> > defined and shall print zero:
>
> > -------------------------------------------------
> > #include<iostream>
> > #include<type_traits>
>
> > struct X;
>
> > int main()
> > {
> >       std::cout<<  (int)std::is_constructible<X const&, int>::value;
> > }
>
> > struct X
> > {
> >       X(int) {}
> > };
> > -------------------------------------------------
>
> > Am I right?
>
> I agree with your interpretation, but the intention is different. The
> intention is that this *should* be a violation of pre-conditions.

OK. What can you say about the following 3 examples:

1)
    #include <iostream>
    #include <type_traits>

    struct B {};
    struct D;

    int main()
    {
        std::cout << (int)std::is_constructible<B *, D *>::value;
        std::cout << (int)std::is_assignable<B *&, D *>::value;
    }

    struct D : B {};

2)
    #include <iostream>
    #include <type_traits>

    struct A;

    struct X
    {
        X(A const &) {}
    };

    int main()
    {
        std::cout << (int)std::is_constructible<X, int>::value;
    }

    struct A
    {
        A(int) {}
    };

3)
    #include <iostream>
    #include <type_traits>

    struct A;

    struct X
    {
        X(A const &) {}
        X(...) {}
    };

    int main()
    {
        std::cout << (int)std::is_constructible<X, int>::value;
    }

    struct A
    {
        A(int) {}
    };

Should they be non-well-defined too?

> is_**_destructible: The current pre-conditions look ok

But the condition does not look clear enough. What should happen when
std::is_destructible is instantiated with cv void, a function type, or
an array of unknown bound type?

> So what are the ideal pre-conditions for providing useful user-support
> but not imposing?

I don't see any ideal solution for this. I think, the following
questions should be answered here:

1. Why exactly existing preconditions are specified and what problem
additional preconditions would solve? Probably, the main goal here is
to let an implementation to diagnose dangerous applications of the
library components. But note that sometimes we can perform an explicit
check of completeness of certain types when we really need in this.

2. What if is_constructible<IncompleteType>::value == false and other
similar equalities would be desirable for somebody somewhere? Do we
have enough real experience to estimate how often such cases may
appear? Personally, I don't.

3. How long list of preconditions we would consider as too long and
unacceptable?

The only thing I would propose is to add the following wording (or,
probably, some improved version of it) to N3242 - 20.9.4.3
[meta.unary.prop] p.6 (and similarly for all other constructs (e.g.
declval<T>() = declval<U>()) whose well-formedness determines
semantics of library components):

    If two different points of instantiation for is_constructible<T,
Args...> give such contrived variable definition different meanings
according to the one definition rule (3.2), the behavior is undefined.

- where the contrived variable definition is

    T t(create<Args>()...);


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Nikolay
3/8/2011 1:56:40 PM
On Mar 8, 2:56 pm, Nikolay Ivchenkov <ts...@mail.ru> wrote:

> The only thing I would propose is to add the following wording (or,
> probably, some improved version of it) to N3242 - 20.9.4.3
> [meta.unary.prop] p.6 (and similarly for all other constructs (e.g.
> declval<T>() = declval<U>()) whose well-formedness determines
> semantics of library components):
> 
>     If two different points of instantiation for is_constructible<T,
> Args...> give such contrived variable definition different meanings
> according to the one definition rule (3.2), the behavior is undefined.
> 
> - where the contrived variable definition is
> 
>     T t(create<Args>()...);

I like this direction and wonder if it needs to be applied elsewhere
as well (perhaps is_convertible?).

-Howard


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Howard
3/8/2011 2:23:44 PM
Reply:

Similar Artilces:

jython and C-c C-c
How do I get C-c C-c to work with jython? I have the jpython command set to jython, and I can start the interpreter with C-C ! and then use C-c C-c, but this is rather frustrating. If I try to use C-c C-c without first starting the interpreter in another window I get wrong type argument: sequencep, jpython Thanks, Dave Cook ...

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta > * open source - preferable, but not 100% necessary what's wrong with using C? Friedrich > what's wrong with using C? Too low level, no built-in garbage collection. -- Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: >> what's wrong with using C? > > Too low level, Well the Smalltalk people say, have a small language and a big library. I assume C's library status beyond that of Smalltalk. > no built-in garbage collection. Use the Boehm Weisser GC. Friedrich "Kevin Albrecht" <kevin@albrecht.net> wrote in message news:<2TiYb.237892$rj7.1641209@twister.tampabay.rr.com>... > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) > ...

Is C# really "better" than C++ or C++0x? How about objective-C?
Microsoft thinks C++ is obsolete and C# is "the future". Apple thinks the same for Objective-C. IMO this is all nonsense. What do you think about this? How "better" really they are? And what about C++0x? On Sun, 17 Apr 2011 16:58:37 +0200, "A" <a@a.a> wrote: >Microsoft thinks C++ is obsolete and C# is "the future". Apple thinks the >same for Objective-C. > >IMO this is all nonsense. I agree. > >What do you think about this? How "better" really they are? And what about >C++0x? > Companies like Microsoft ...

Why is there no std::variant in C++0x?
Hello, Thanks to the variadic templates, the presence of the tuples in the STL has become obvious. But what about the variants? I recently had to write an implementation of boost::variant using variadic templates. I could make it without any difficulty. Hence, I thought the introduction of an std::variant template in the C++0x's STL would be as obvious as std::tuple. I've been surprised to notice that there wasn't any plan to do this. Some may argue that the unrestricted unions will do the job, but IMHO it's a pity to incorporate in the core language a feature ...

slime C-c C-c annoyance
Does anyone have a good workaround for this problem other than: just be careful! When I've compiled a large package and slime has given me a *slime-compilation* buffer, I like to work through this buffer issue by issue, fixing the errors, warnings, etc. But If I ever press C-c C-c in the editor window while fixing an error, slime destroys the *(slime-compilation* buffer with the compilation output of C-c C-c. Jim Newton <jimka.issy@gmail.com> writes: > Does anyone have a good workaround for this problem other than: just be careful! > > When I've compiled a ...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

C as a Subset of C++ (or C++ as a superset of C)
Isn't it a lame use of human time and effort to maintain completely separate C and C++ standards? As in the words of Betty White about Facebook: "It seems like an incredible waste of time". Why don't the two standards groups get together and agree on a common specification for the ground which both standards cover? There would still be two separate standards, but they'd both be exactly the same for the common ground. The common ground document could be referred to by both standards instead of being maintained by both groups in individual efforts resulting in...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

c------->c++ and c++------>c
We can write c program in turbo c++ editor.But reverse is not true why? i.e The program will not compile if u write c++ program in turbo c editor vim wrote: > We can write c program in turbo c++ editor.But reverse is not true why? > i.e The program will not compile if u write c++ program in turbo c > editor This isn't about C; this is about some editor. Why the fircone should /we/ know? Ask in a relevant group. [And /why/, in an editor specialised to some specific programming languages, would you expect it to compile a /different/ one? Would you expect turbo perl to compi...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! Throne Software wrote: > Throne Software has opened up C, C++ and C# Forums at: > > http://www.thronesoftware.com/forum/ For all of your forums newsgroups already exist. > Join us! Why? Don't see any reason to support your marketing. ...

C,, C++, Java, C#
I come from C,C++,Java and C#. What can SmallTalk do for me and for what cost? Regarding the Squeak thing, it's interesting though confusing. Is it an IDE? Why are the menus so wacky? "DM McGowan II" <nospam@nospam.net> wrote in message news:PLednX2vnLd11IncRVn-rA@comcast.com... > I come from C,C++,Java and C#. What can SmallTalk do for me ...? Ask not what Smalltalk can do for, but what can you do with Smalltalk. :-) In very few words, it significantly reduces time to market, while enhancig the development experience. This is because: 1. It...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! In article <1120963701.862698.160260@g14g2000cwa.googlegroups.com>, Throne Software <mail@thronesoftware.com> writes >Throne Software has opened up C, C++ and C# Forums at: > >http://www.thronesoftware.com/forum/ > >Join us! Why? The beauty of news groups is that they come to me I don't have to go to them. Also all the people who have been around a while know what they are doing and are here. I noticed that there are some C and C++ Forums on another system...

c,c++,obj-c
Of the 3 languages titled in this post is c++ older than obj-c ? Would someone experienced in C be able to dive right into C++ rather than obj-c ? Java is out for me now except applet programming I think I'm going to go with just C and C++. Bill Bill Cunningham wrote: > Of the 3 languages titled in this post is c++ older than obj-c ? Why does that matter? Do you want to use an old language? Try Fortran or LISP. > Would > someone experienced in C be able to dive right into C++ rather than > obj-c ? Not quite dive in, at least not into the OO parts of C++. ...

About C and C++
Hello... I will resume it like this: On the criterias of "complexity" and "difficulty", the C and C++ programming languages are more complex and difficult than Object Pascal for example, so since they are more complex and difficult they are likely to create something like a darwinian filter who don't let the weaker humans among us humans to cross or to climb the social ladder, this is why i think that C and C++ do participate to social darwinism, this is why i say that C and C++ are bad. Thank you, Amine Moulay Ramdane. aminer <aminer@toto...

About C and C++...
Hello, I have saw some programmers talking about C on the C's forums... But as you have seen me talking before on my post titled "Software life cycle" , you have noticed that i have talked about the criterions that is "Maintainability" and "modifiability", what i don't like in C is that if you want to group efficiently functions and some propoerties that are shared inside an object , you can not do that efficiently as can do Object Pascal or C++, if you are writing in C you have to use global variables, but that's not good for "maintenance" and "clarity" of the code, in C++ or Object pascal you will not use global variables but you will use an object that enhance the clarity and maintainability... this is why i don't like C, other than that since Java is garbage collected it enhance the "Reliability" and "Security" criterions, ADA also is good at Reliability and security, i think C and C++ score less on those criterions that are reliability and security than Java or ADA. Thank you, Amine Moulay Ramdane. Hello, Even if you can use structs to group functions and there shared variables in C, that's not as efficient as C++ or Object Pascal, in C++ or Object Pascal you can use public and private... properties and that's efficient and you can use also generics and lambda expressions to write less code and to easy maintenanc...

C++ or C?
somebody told me that c++ is superior to c while others insist that c++ is just a junk. I don't know which to follow.I want to know exactly the difference between them, and their respective advantage and disadvantage. Magcialking wrote: > somebody told me that c++ is superior to c while others insist that > c++ is just a junk. > I don't know which to follow.I want to know exactly the difference > between them, and their respective advantage and disadvantage. www.google.com and read about the differences until you're blue in the face. Oh, while you're at it, loo...

What After C and C++?
First it was C, then C++, what comes next? "Penna Elabi" <terebinthus@go.com> wrote in message news:77081966.0311290846.3d5a7064@posting.google.com... > First it was A whole bunch of computer languages, then >C, then a whole bunch more computer languages, then >C++, what comes next? A whole bunch more. So what? Did you have a question about C++ (which is the *only* topic here) ? -Mike "Penna Elabi" <terebinthus@go.com> wrote... > First it was C, then C++, what comes next? Who cares? This newsgroup is concerned with C++, not with what c...

C... Why not c++?
Someone can exaplain me why use C instead C++? Until now i've never found exaplanation for this. Every project written in C on which i've worked could be written in c++, and when in nowadays happen still to see C code i really don't understand why the same things cannot be written in c++. Using c++ it's possble to reduce developing time achieving the same result. Can you give me a valid reason for C? Simple enough, the OO & template features are not needed on some projects targeted to OS kernel development and device driver development and other low-level libraries. Moreov...

C++ and C#
Hi, We have some common functionality that has to run with both C++ and C#. What would be the best way to design this. One of the approaches we could think of is to 1. create an exe for the common code 2. create api's in C++ and C# to invoke this exe 3. Put the api's in a library each for C# and C++ Would help if we could get some alternatives to do this. Thanks and Regards, M Shetty mshetty@mail.com wrote: > Hi, > > We have some common functionality that has to run with both C++ and C#. > What would be the best way to design this. > > One of the approaches we ...

C to C++
Hi all In C I have previously created structures that contain themselves e.g. typdef struct Node_tag { struct Node_tag ptrNodes; float nodeNumber } Node; This worked fine, but trying to do the same in C++ doesn't work, any suggestions. Thanks daveR This day of Fri, 30 Apr 2004 10:39:02 +0100, "Charlotte Dean" <charlottedean@(NO5PAM)sheffield17a.fsnet.co.uk> proclaimed: >Hi all > >In C I have previously created structures that contain themselves e.g. > >typdef struct Node_tag { > ...

More about C and C++
Hello... I have wrote: >I will resume it like this: >On the criterias of "complexity" and "difficulty", the C and C++ >programming languages are more complex and difficult than Object >Pascal for example, so since they are more complex and difficult they >are likely to create something like a darwinian filter who don't let >the weaker humans among us humans to cross or to climb the social >ladder, this is why i think that C and C++ do participate to social >darwinism, this is why i say that C and C++ are bad. Josep...

About C and C++
Hello... I will resume it like this: On the criterias of "complexity" and "difficulty", the C and C++ programming languages are more complex and difficult than Object Pascal for example, so since they are more complex and difficult they are likely to create something like a darwinian filter who don't let the weaker humans among us humans to cross or to climb the social ladder, this is why i think that C and C++ do participate to social darwinism, this is why i say that C and C++ are bad. Thank you, Amine Moulay Ramdane. On Sunday, 8 June 2014...

About C and C++
Hello, I will resume it like this: On the criterias of "complexity" and "difficulty", the C and C++ programming languages are more complex and difficult than Object Pascal for example, so since they are more complex and difficult they are likely to create something like a darwinian filter who don't let the weaker humans among us humans to cross or to climb the social ladder, this is why i think that C and C++ do participate to social darwinism, this is why i say that C and C++ are bad. Thank you, Amine Moulay Ramdane. On Sun, 08 Jun 2014 06:1...

Web resources about - Preconditions and semantics of std::is_constructible and std::is_assignable in N3242 (C++0x draft) - comp.lang.c++.moderated

Resources last updated: 2/23/2016 7:57:15 PM