These are chat archives for boostorg/hana

16th
Mar 2016
Barrett Adair
@badair
Mar 16 2016 00:07
The same implementation is used for deep_decay, which is the base case for the decorate_like recursion
Louis Dionne
@ldionne
Mar 16 2016 13:08
Interesting. I don’t think that fits in Hana, but perhaps in Boost.TypeTraits. What I’ve seen before is a simple version of this called copy_cv, which copies the cv-qualifiers of a type.
This is super useful sometimes.
Jason Rice
@ricejasonf
Mar 16 2016 16:27
Do you guys know if this is some kind of sfinae trick or something? How are these specialized or overloaded on return type? I would expect something like
template <> const blah *Type::getAs<blah>().
template <> const TypedefType *Type::getAs() const {
  return getAsSugar<TypedefType>(this);
}

template <> const TemplateSpecializationType *Type::getAs() const {
  return getAsSugar<TemplateSpecializationType>(this);
}
Louis Dionne
@ldionne
Mar 16 2016 16:34
I wouldn’t think this is valid C++. Is it? Where from?
Jason Rice
@ricejasonf
Mar 16 2016 16:34
clang::Type
Louis Dionne
@ldionne
Mar 16 2016 16:34
Assuming template <typename T> … Type::getAs(); before of course.
Well then it’s definitely valid C++.
Jason Rice
@ricejasonf
Mar 16 2016 16:37
here is the orginal template declaration
  /// Member-template getAs<specific type>'.  Look through sugar for
  /// an instance of \<specific type>.   This scheme will eventually
  /// replace the specific getAsXXXX methods above.
  ///
  /// There are some specializations of this member template listed
  /// immediately following this class.
  template <typename T> const T *getAs() const;
Louis Dionne
@ldionne
Mar 16 2016 16:44
Ok. A function can’t be overloaded on return type. But this is specialization, not overloading. And it’s not specializing “on return type”, it’s just specializing.
I think when they write template <> const T* Type::getAs(), the compiler just deduces the T from the base template declaration.
And says “oh, you meant template <> const T* Type::getAs<T>()”.
Jason Rice
@ricejasonf
Mar 16 2016 16:51
still have to call it .getAs<blah>()
Louis Dionne
@ldionne
Mar 16 2016 17:08
Yeah, no surprise there
Jason Rice
@ricejasonf
Mar 16 2016 17:31
had to try :P