nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

Template Generierung explizit erlauben/verbieten

Von: Helmut Zeisel (zei2006q1@liwest.at) [Profil]
Datum: 10.09.2009 11:06
Message-ID: <c93113c4-977a-43a2-9c62-6e0ed0d273ea@j4g2000yqa.googlegroups.com>
Newsgroup: de.comp.lang.iso-c++
Ich möchte gerne die Generierung von Template Code je nach Typ
explizit erlauben oder verbieten. Im Prinzip ist mir klar, wie das
geht. Ein Beispiel, wie es funktioniert, steht im Anhang.

Frage: gibt es dafür (benannte?) Quasi-Standards/Pattern, damit ich
nicht lange erklären muss, was ich mir dabei gedacht habe?

Helmut

======== Codebeispiel ==========

struct disallowed {};
struct allowed
{
typedef int allowed_t;
};

template<typename T> class mytraits: public disallowed {};
template<> class mytraits<double>: public allowed {};

class myclass
{
public:
template<typename T> operator T()
{
typedef typename mytraits<T>::allowed_t allowed_t;
T result=0;
return result;
}
private:
};

static myclass d;
static double c1=d; // OK
static int c2=d;    // Compile fails

[ Auf dieses Posting antworten ]

Antworten