Retourner au contenu associé (dépêche : Retard(s) pour la prochaine version de C++)
Posté par monsieurmoche le 27 juillet 2009 à 20:58. En réponse à la dépêche Retard(s) pour la prochaine version de C++. Évalué à 1.
/* * Utility types */ typedef char yes_type; struct no_type { char padding[8]; }; /* * list_node type trait */ namespace list_node_check { template<class T> static yes_type check_sig(typename T::item*); template<class T> static no_type check_sig(...); } template<class T> struct is_list_node { static const bool value = sizeof(list_node_check::check_sig(0)) == sizeof(yes_type); }; /* * optional_node type trait */ template<class T> struct is_optional_node { static const bool value = false; }; template<class T> struct is_optional_node<syntax_nodes::optional_node> { static const bool value = true; };
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
[^] # Re: Les concepts, c'est du sucre
Posté par monsieurmoche . En réponse à la dépêche Retard(s) pour la prochaine version de C++. Évalué à 1.
/*
* Utility types
*/
typedef char yes_type;
struct no_type
{
char padding[8];
};
/*
* list_node type trait
*/
namespace list_node_check
{
template<class T>
static
yes_type
check_sig(typename T::item*);
template<class T>
static
no_type
check_sig(...);
}
template<class T>
struct is_list_node
{
static const bool value = sizeof(list_node_check::check_sig(0)) == sizeof(yes_type);
};
/*
* optional_node type trait
*/
template<class T>
struct is_optional_node
{
static const bool value = false;
};
template<class T>
struct is_optional_node<syntax_nodes::optional_node>
{
static const bool value = true;
};
Un exemple d'intuitivité.
Et encore, je suis sûr qu'on peut trouver des alternatives bien pires à ce qu'auraient proprement permis les concepts.