1

I was looking at an example implementation of binder1st, that looks like this:

template <class Operation, class T>
  binder1st<Operation> bind1st (const Operation& op, const T& x)
{
  return binder1st<Operation>(op, typename Operation::first_argument_type(x));
}

What is the meaning of typename Operation::first_argument_type(x). I understand first_argument_type to be a typename, but belonging to the binary_function base class. It looks to me that it is a function belonging to namespace Operation - in which case, why is typename used here?

BeeBand
  • 10,953
  • 19
  • 61
  • 83
  • 2
    It's not a function, but a function-style cast to the type `Operation::first_argument_type`. – catscradle Sep 04 '13 at 13:54
  • Is a function-style cast the same thing as what Stefano describes below ( the constructor of `Operation::first_argument_type`, taking a `const T&`)? – BeeBand Sep 04 '13 at 13:59
  • 2
    @BeeBand Yes, the function-style cast is invoking the constructor. – Konrad Rudolph Sep 04 '13 at 14:04
  • @BeeBand Yes, but depending on exact types, appropriate `T::operator Type()` could also be called. – catscradle Sep 04 '13 at 14:09
  • Ok great, I was just wondering what the purpose of this cast was - it seems that this is to verify during compilation that `Operation` has the nested typedef of `first_argument_type`. – BeeBand Sep 04 '13 at 14:29

1 Answers1

0

it means that the qualified name that follows the typename keyword (i.e. Operation::first_argument_type) is to be interpreted as the name of a (dependent) type.

You can read the full explanation of the keyword typename (which also has another, different usage) here.

Stefano Falasca
  • 8,837
  • 2
  • 18
  • 24
  • In this context, is `x` being cast to the type `Operation::first_argument_type`? – BeeBand Sep 04 '13 at 13:54
  • 1
    nope, the `Operation::first_argument_type` constructor taking a `const T&` argument is being invoked. – Stefano Falasca Sep 04 '13 at 13:57
  • slightly off topic, read here http://herbsutter.com/2013/05/09/gotw-1-solution/ , as it could be interesting. For example, I would write typename Operation::first_argument_type((x)), just to play on the safe side – Stefano Falasca Sep 04 '13 at 14:00