Topic: Compileable


Author: "Ludwig Pumberger" <pumberger@direkt.at>
Date: Sat, 23 Mar 2002 23:47:07 GMT
Raw View
A key word compileable could be usefull in C++:

compileable(5+2); //true
compileable(std::vector<int>() + 2); //false

Of course compileable can only check for semantic correctness and not for
any syntactic errors:

compileable(+); //Compiler error

It could be used to determine wheter a type is POD:

template <typename T>
union PODChecker
{
    T t;
};

template <typename T>
struct is_pod
{
    enum {result = compileable(PODChecker<T>)};
};

The compiler should here check wheter it is possible to instantite
PODChecker for T. If T isn't POD, PODChecker can't be instantiated and
compileable evaluates to false.

template <typename T>
T make(); //never implemented

template <typename T>
struct is_virtual
{
    enum {result = dynamic_cast<void*>(make<T*>())};
};

dynamic_cast is only supported for typed which have at least one virtual
memberfunction.

compileable(make<T>().func(make<Arg1>(),make<Arg2>())) could be use to
determine if there is a member-function func which takes two parameters of
type Arg1 and Arg2.

//No entity X is visible for the compiler
compileable(X);

This should result in a compiler-error and not return false.

I think such a keyword could extent the possibilities of C++
meta-programming a lot.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Richard Smith" <richard@ex-parrot.com>
Date: Sun, 24 Mar 2002 02:28:09 GMT
Raw View
"Ludwig Pumberger" <pumberger@direkt.at> wrote in message
news:a7i43k$ldau2$1@ID-133423.news.dfncis.de...
>
> I think such a keyword could extent the possibilities of C++
> meta-programming a lot.

So could a clarification to 14.8.2/2, if it were in the right direction.

--
Richard Smith


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]