Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) {

const TemplateDecl *TD =
Specialization->getTemplateName().getAsTemplateDecl();
if (!TD || TD->getName() != "enable_if")
if (!TD || TD->getName() != "enable_if" || !TD->isInStdNamespace())
return std::nullopt;

int NumArgs = SpecializationLoc.getNumArgs();
Expand All @@ -101,7 +101,7 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) {

const TemplateDecl *TD =
Specialization->getTemplateName().getAsTemplateDecl();
if (!TD || TD->getName() != "enable_if_t")
if (!TD || TD->getName() != "enable_if_t" || !TD->isInStdNamespace())
return std::nullopt;

if (!Specialization->isTypeAlias())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,3 +756,33 @@ abs(const number<T, ExpressionTemplates> &v) {
}

}

// NOLINTBEGIN
namespace custom {
template <bool B, class T = void> struct enable_if { };

template <class T> struct enable_if<true, T> { typedef T type; };

template <bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;

} // namespace custom
// NOLINTEND
Comment on lines +760 to +770
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the name of the namespace, this block is identical to the namespace std block at the beginning of this test file. I don't understand the purpose of the NOLINTBEGIN/NOLINTEND markers, so I just copied them blindly. Feel free to suggest removing them if you know that they are superfluous (in that case I'll probably remove them from the beginning of the file as well).


namespace use_custom {
// We cannot assume anything about the behavior of templates that happen to be
// named `enable_if` or `enable_if_t` if they are not declared in the namespace
// `std`. (E.g. the first template parameter of `boost::enable_if` is a class
// and not a boolean and `boost::enable_if<Cond, T>` is equivalent to
// `std::enable_if<Cond::value, T>`.)

template <typename T>
typename custom::enable_if<T::some_value, Obj>::type custom_basic() {
return Obj{};
}

template <typename T>
custom::enable_if_t<T::some_value, Obj> custom_basic_t() {
return Obj{};
}
}