Boost logo

Boost :

Subject: Re: [boost] [xint] Design Question
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2010-06-17 01:06:51

Hash: SHA1

On 06/17/2010 12:00 AM, Scott McMurray wrote:

>> Do you know of any way, short of making two nearly-identical copies
>> of the integer_t class template, to provide different functions? I
>> tried using multiple templated base classes, but the compiler
>> seemed unable to find the inherited functions at all that way, for
>> reasons I don't understand.
> SFINAE, through enable_if and disable_if?
> Without more details, it's hard to know what you're asking for.

When I went looking for a description of policy-based design, it
appeared to use multiple base classes, each one providing the functions
and data specific to its own policy. But when I tried adapting my
existing design to that, by putting the functions specific to each
policy into their own classes, the compiler couldn't seem to find the
functions that should have been inherited. Let me see if I can come up
with some code to demonstrate the problem...

Hm. I think I've figured it out now: for some reason, at least under
GCC, this code would fail:

- --------------------------8<------------------------------

#include <iostream>

using std::cout;
using std::endl;

template <bool Value>
class Policy1 {
    void test_policy1() {
        cout << "Policy1: " << Value << endl;

template <int Value>
class Policy2 {
    void test_policy2() {
        cout << "Policy2: " << Value << endl;

template <bool P1, int P2>
class CombinePolicies: public Policy1<P1>, public Policy2<P2> {
    void test() {

int main() {
    CombinePolicies<true, 3> t;

- --------------------------8<------------------------------

The compiler reports "there are no arguments to 'test_policy1' that
depend on a template parameter, so a declaration of 'test_policy1' must
be available". Same error for test_policy2. I could call either one from
*outside* the CombinePolicies class, but from inside, they would always
give that error.

As I said above, I think I figured out the solution. While writing that
code just now, it occurred to me to try this...


...and it worked. But I don't understand why it failed in the first
place. Those two function names are unique in the class, and they're
obviously inherited because I can call them from outside the class. Why
aren't they visible without the base class name from *within* the
combined class?
- --
Chad Nelson
Oak Circle Software, Inc.
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla -


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