Re: Fwd: Re: [sigc] [Fwd: libsigc++ 1.9.13 fails on Solaris 9 sparc] [martin-ml hippogriff de]



Am 2004.02.23 13:33 schrieb(en) Damien Carbery:
No go. "Overloading ambiguity" with is_base_and_derived.
Log attached.

Well, if the first two variants fail to compile, we can
still try the other two. I'm attaching the same file after
commenting out the offending tests. Please try again.

Thanks!

 Martin


Martin Schulze wrote:
Am 2004.02.20 19:08 schrieb(en) Damien Carbery:

Looks like similar issues as last time. Log attached.


That's bad news. Could you just try to compile the test program
I'm attaching and e-mail me the output of the binary? We need to
find a working flavour of is_base_and_derived<>!
I did some research and obviously boost are using the same sizeof()
trick than us. There doesn't seem to be an alternative.

I had trouble applying the patch - I'm not very good at that.


Sorry for that.

 patch -p0 < ../base_and_derived.patch

works for me in directory libsigc++-1.9.14.

Regards,

 Martin

> # CC: Sun C++ 5.5 Patch 113817-03 2003/10/14
$ CC test_base_and_derived.cc
"test_base_and_derived.cc", line 115: Error: Overloading ambiguity
between "static is_base_and_derived<A, D>::test::is_base_class_(const
void*)" and "static is_base_and_derived<A,
D>::test::is_base_class_(A*)".
"test_base_and_derived.cc", line 236:     Where: While specializing
"is_base_and_derived<A, D>".
"test_base_and_derived.cc", line 236:     Where: Specialized in
non-template code.
"test_base_and_derived.cc", line 142: Error: Overloading ambiguity
between "static is_base_and_derived1<A,
B>::test::is_base_class_(void*)" and "static is_base_and_derived1<A,
B>::test::is_base_class_(A*)".
"test_base_and_derived.cc", line 243:     Where: While specializing
"is_base_and_derived1<A, B>".
"test_base_and_derived.cc", line 243:     Where: Specialized in
non-template code.
"test_base_and_derived.cc", line 142: Error: Overloading ambiguity
between "static is_base_and_derived1<A,
D>::test::is_base_class_(void*)" and "static is_base_and_derived1<A,
D>::test::is_base_class_(A*)".
"test_base_and_derived.cc", line 245:     Where: While specializing
"is_base_and_derived1<A, D>".
"test_base_and_derived.cc", line 245:     Where: Specialized in
non-template code.
3 Error(s) detected.

/*
 * Copyright 2002, The libsigc++ Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <iostream>
 

template <class T_type>
struct type_trait
{
  typedef T_type  type;
  typedef T_type& pass;
  typedef const T_type& take;
  typedef T_type* pointer;
  static  T_type  instance(); /* not implemented */  
};

template <class T_type, int N>
struct type_trait<T_type[N]>
{
  typedef T_type*  type;
  typedef T_type*& pass;
  typedef const T_type*& take;
  typedef T_type** pointer;
  static  T_type*  instance(); /* not implemented */  
};

template <class T_type>
struct type_trait<T_type&>
{
  typedef T_type  type;
  typedef T_type& pass;
  typedef T_type& take;
  typedef T_type* pointer;
  static  T_type& instance(); /* not implemented */ 
};

template <class T_type>
struct type_trait<const T_type&>
{
  typedef const T_type  type;
  typedef const T_type& pass;
  typedef const T_type& take;
  typedef const T_type* pointer;
  static  const T_type& instance(); /* not implemented */ 
};

/*template <class T_type>
struct type_trait<reference_wrapper<T_type> >
{
  typedef T_type  type;
  typedef T_type& pass;
  typedef T_type& take;
  typedef T_type* pointer;
  static  T_type& instance();
};

template <class T_type>
struct type_trait<const_reference_wrapper<T_type> >
{
  typedef T_type  type;
  typedef T_type& pass;
  typedef const T_type& take;
  typedef T_type* pointer;
  static  T_type& instance();
};*/

template<>
struct type_trait<void>
{
  typedef void  type;
  typedef void  pass;
  typedef void  take;
  typedef void* pointer;
  static  void  instance(); /* not implemented */
};


/** From Esa Pulkkin:
 * Compile-time determination of base-class relationship in C++
 * (adapted to match the syntax of boost's type_traits library).
 */
 
/* doesn't seem to work with the SUN Forte: */
/*template <class T_base, class T_derived>
struct is_base_and_derived
{
private:
  struct big {
    char memory[64];
  };

  struct test {
    static big  is_base_class_(const void*);
    static char is_base_class_(typename type_trait<T_base>::pointer);
  };

public:
  static const bool value =
    sizeof(test::is_base_class_((typename type_trait<T_derived>::pointer)0)) ==
    sizeof(char);
};

template <class T_base>
struct is_base_and_derived<T_base, T_base>
{
  static const bool value = true;
};*/


/* test 1: */
/*template <class T_base, class T_derived>
struct is_base_and_derived1
{
private:
  struct big {
    char memory[64];
  };

  struct test {
    static big  is_base_class_(void*);
    static char is_base_class_(typename type_trait<T_base>::pointer);
  };

public:
  static const bool value =
    sizeof(test::is_base_class_((typename type_trait<T_derived>::pointer)0)) ==
    sizeof(char);
};

template <class T_base>
struct is_base_and_derived1<T_base, T_base>
{
  static const bool value = true;
};*/


/* test 2: */
template <class T_base, class T_derived>
struct is_base_and_derived2
{
/*private:*/
  struct big {
    char memory[64];
  };

  struct test {
    static big  is_base_class_(...);
    static char is_base_class_(typename type_trait<T_base>::pointer);
  };

/*public:*/
  static const bool value =
    sizeof(test::is_base_class_((typename type_trait<T_derived>::pointer)0)) ==
    sizeof(char);
};

template <class T_base>
struct is_base_and_derived2<T_base, T_base>
{
  static const bool value = true;
};


/* test 3: */
template <class T_base, class T_derived>
struct is_base_and_derived3
{
/*private:*/
  struct big {
    char memory[64];
  };

  struct test {
    static big  is_base_class_(...);
    static char is_base_class_(typename type_trait<T_base>::pointer);
  };

  static typename type_trait<T_derived>::pointer derived;

/*public:*/
  static const bool value =
    sizeof(test::is_base_class_(derived)) ==
    sizeof(char);
};

template <class T_base>
struct is_base_and_derived3<T_base, T_base>
{
  static const bool value = true;
};



struct A {};
struct B : A {};
struct C {};
struct D : B {};
/*template <class T_type, bool I_islambda = is_base_and_derived<A, T_type>::value> struct A_test;
template <class T_type> struct A_test<T_type, false> { static const bool value=false; };
template <class T_type> struct A_test<T_type, true>  { static const bool value=true; };
template <class T_type, bool I_islambda = is_base_and_derived1<A, T_type>::value> struct A_test1;
template <class T_type> struct A_test1<T_type, false> { static const bool value=false; };
template <class T_type> struct A_test1<T_type, true>  { static const bool value=true; };*/
template <class T_type, bool I_islambda = is_base_and_derived2<A, T_type>::value> struct A_test2;
template <class T_type> struct A_test2<T_type, false> { static const bool value=false; };
template <class T_type> struct A_test2<T_type, true>  { static const bool value=true; };
template <class T_type, bool I_islambda = is_base_and_derived3<A, T_type>::value> struct A_test3;
template <class T_type> struct A_test3<T_type, false> { static const bool value=false; };
template <class T_type> struct A_test3<T_type, true>  { static const bool value=true; };

int main() {
  std::cout << "is_base_and_derived test ..." << std::endl;

  std::cout << "sizeof(char): " << sizeof(char) << std::endl;
  std::cout << "sizeof(is_base_and_derived<A,B>::big): " << sizeof(is_base_and_derived2<A,B>::big) << std::endl;

/*  std::cout << "is_base_and_derived<A,A>: " << is_base_and_derived<A,A>::value << std::endl;
  std::cout << "is_base_and_derived<A,B>: " << is_base_and_derived<A,B>::value << std::endl;
  std::cout << "is_base_and_derived<A,C>: " << is_base_and_derived<A,C>::value << std::endl;
  std::cout << "is_base_and_derived<A,D>: " << is_base_and_derived<A,D>::value << std::endl;
  std::cout << "A_test<A>: " << A_test<A>::value << std::endl;
  std::cout << "A_test<B>: " << A_test<B>::value << std::endl;
  std::cout << "A_test<C>: " << A_test<C>::value << std::endl;
  std::cout << "A_test<D>: " << A_test<D>::value << std::endl;

  std::cout << "is_base_and_derived1<A,A>: " << is_base_and_derived1<A,A>::value << std::endl;
  std::cout << "is_base_and_derived1<A,B>: " << is_base_and_derived1<A,B>::value << std::endl;
  std::cout << "is_base_and_derived1<A,C>: " << is_base_and_derived1<A,C>::value << std::endl;
  std::cout << "is_base_and_derived1<A,D>: " << is_base_and_derived1<A,D>::value << std::endl;
  std::cout << "A_test1<A>: " << A_test1<A>::value << std::endl;
  std::cout << "A_test1<B>: " << A_test1<B>::value << std::endl;
  std::cout << "A_test1<C>: " << A_test1<C>::value << std::endl;
  std::cout << "A_test1<D>: " << A_test1<D>::value << std::endl;*/

  std::cout << "is_base_and_derived2<A,A>: " << is_base_and_derived2<A,A>::value << std::endl;
  std::cout << "is_base_and_derived2<A,B>: " << is_base_and_derived2<A,B>::value << std::endl;
  std::cout << "is_base_and_derived2<A,C>: " << is_base_and_derived2<A,C>::value << std::endl;
  std::cout << "is_base_and_derived2<A,D>: " << is_base_and_derived2<A,D>::value << std::endl;
  std::cout << "A_test2<A>: " << A_test2<A>::value << std::endl;
  std::cout << "A_test2<B>: " << A_test2<B>::value << std::endl;
  std::cout << "A_test2<C>: " << A_test2<C>::value << std::endl;
  std::cout << "A_test2<D>: " << A_test2<D>::value << std::endl;

  std::cout << "is_base_and_derived3<A,A>: " << is_base_and_derived3<A,A>::value << std::endl;
  std::cout << "is_base_and_derived3<A,B>: " << is_base_and_derived3<A,B>::value << std::endl;
  std::cout << "is_base_and_derived3<A,C>: " << is_base_and_derived3<A,C>::value << std::endl;
  std::cout << "is_base_and_derived3<A,D>: " << is_base_and_derived3<A,D>::value << std::endl;
  std::cout << "A_test3<A>: " << A_test3<A>::value << std::endl;
  std::cout << "A_test3<B>: " << A_test3<B>::value << std::endl;
  std::cout << "A_test3<C>: " << A_test3<C>::value << std::endl;
  std::cout << "A_test3<D>: " << A_test3<D>::value << std::endl;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]