Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #243

[C++0x] Member accessibility and decltype problem

From Jamboree<tongari95@gmail.com>
Newsgroups comp.std.c++
Subject [C++0x] Member accessibility and decltype problem
Date 2011-08-24 14:52 -0700
Organization albasani.net
Message-ID <f68571db-4f70-4de8-9cea-eb17bda1dcfd@a8g2000pro.googlegroups.com> (permalink)

Show all headers | View raw


Greetings,

I have a problem using decltype with some expression which involves
the private function call of some class.

I'm not sure it's a g++ bug or it's standard conformed, I'm using g+
+4.5.2/MinGW.

The following is a *contrived* example that illustrates the problem, I
hope you can get the idea:

--------------------------------------------------------------------------
// A non-member non-friend utility that needs to deduce the result
type of T::call(p).
template<class T, class P>
auto indirect_call(P p) ->  decltype(T::call(p))
{
     return T::call(p);
}

class A
{
     //
     // These ought to be used internally.
     //
     void private_fn() {}

     typedef void private_fn_result_type;

     struct UseDecltype
     {
         template<class P>
         static
         auto call(P p) ->  decltype(p->private_fn())
         {
             return p->private_fn();
         }
     };

     struct UseTypedef
     {
         template<class P>
         static
         A::private_fn_result_type call(P p)
         {
             return p->private_fn();
         }
     };

public:

     void use_decltype() // This NOT compiles
     {
         indirect_call<UseDecltype>(this);
     }

     void use_typedef() // This compiles
     {
         indirect_call<UseTypedef>(this);
     }
};
--------------------------------------------------------------------------
UseDecltype&  UseTypedef are both private of A, but UseXXX::call is
public-callable so we can use indirect_call<T>, but note that
indirect_call is an external utility which is neither member nor
friend.
In the case of UseTypedef, it works fine even
A::private_fn_result_type is private;
In the case of UseDecltype, it fails to compile because the compiler
complains that private_fn() which used in decltype is private of A...

The problem here:
Even though UseDecltype::call is public to indirect_call, but its
deduced type isn't, hmmm....

Could anybody shed some light on this matter?



-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | Next | Find similar


Thread

[C++0x] Member accessibility and decltype problem Jamboree<tongari95@gmail.com> - 2011-08-24 14:52 -0700

csiph-web