Boost logo

Boost :

Subject: Re: [boost] Workaround for compiler bugs
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2010-12-09 05:35:13

Edward Diener <eldiener_at_[hidden]> writes:

> I will continue to look for a workaround for VC9 and earlier, as I
> think my library should be usable by VC9, VC8, and perhaps
> VC7.1. Thanks for your neat solution for VC10 !

The following works with VC8, VC10 and g++ 4.4. It causes an Internal
Compiler Error with VC7.1 though :-(

#include <iostream>

typedef char small_type;

struct large_type
    small_type dummy[2];

template<bool,typename T>
struct enable_if;

template<typename T>
struct enable_if<true,T>
    typedef T type;

template<typename T,typename DT>
struct has_member_cMem_of_type
    template<typename U>
    static small_type check2(DT (U::*));
    template<typename U>
    static large_type check2(U);

    template<typename U>
    static typename enable_if<
    template<typename U>
    static large_type has_matching_member(...);
    static const bool value=sizeof(has_matching_member<T>(0))==sizeof(small_type);

struct Gipf { };

struct Dvonn {
    Gipf cMem;

struct Tzaar {
    int cMem;

struct Yinsh {
    int Zertz;
    void cMem();

struct Derived:

int main() {
    std::cout<<"one:" <<has_member_cMem_of_type<Dvonn, Gipf>::value<<std::endl;
    std::cout<<"two" ": "<<!has_member_cMem_of_type<Dvonn, int>::value<<std::endl;

    std::cout<<"three" ": "<<!has_member_cMem_of_type<Tzaar, Gipf>::value<<std::endl;
    std::cout<<"four" ": "<< has_member_cMem_of_type<Tzaar, int>::value<<std::endl;

    std::cout<<"five" ": "<<!has_member_cMem_of_type<Yinsh, Gipf>::value<<std::endl;
    std::cout<<"six" ": "<<!has_member_cMem_of_type<Yinsh, int>::value<<std::endl;

    std::cout<<"seven" ": "<<has_member_cMem_of_type<Derived, Gipf>::value<<std::endl;
    std::cout<<"eight" ": "<<!has_member_cMem_of_type<Derived, int>::value<<std::endl;


Author of C++ Concurrency in Action
just::thread C++0x thread library   
Just Software Solutions Ltd
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

Boost list run by bdawes at, gregod at, cpdaniel at, john at