Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #590

Re: detecting incomplete type

Message-ID <42dfae8a-8b98-46ec-9a7b-1f9dac421df5@googlegroups.com> (permalink)
Newsgroups comp.std.c++
From James Kanze <james.kanze@googlemail.com>
Subject Re: detecting incomplete type
Organization unknown
References <kepfmi$gfm$1@news.ett.com.ua>
Date 2013-02-07 02:32 -0600

Show all headers | View raw


On Wednesday, February 6, 2013 7:50:31 AM UTC, Balog Pal wrote:
> What is a standard way to tell whether a type is complete or not? In a
> way usable in say static_assert?

> In boost code I saw sizeof(T) used that worked fine on gcc and msvc
> which make that 0. But I recently read the section on sizeof that
> tells it used with incomplete type makes the program ill-formed.

SFINAE should help here.  Something along the lines of:

    template <typename T>
    class Derived : public T {};

    TrueType discrim( Derived<T>* );
    FalseTpe discrim( ... );

and then something like `sizeof( discrim<T>( 0 ) )`.  If the
type is incomplete, the instantiation of Derived<T> fails,

--
James


[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

detecting incomplete type Balog Pal <pasa@lib.hu> - 2013-02-06 01:50 -0600
  Re: detecting incomplete type Daniel Krügler <daniel.kruegler@googlemail.com> - 2013-02-07 02:08 -0600
  Re: detecting incomplete type James Kuyper <jameskuyper@verizon.net> - 2013-02-07 02:31 -0600
  Re: detecting incomplete type James Kanze <james.kanze@googlemail.com> - 2013-02-07 02:32 -0600

csiph-web