[PATCH] D59142: YAMLIO: Improve template arg deduction for mapOptional

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 14:06:15 PDT 2019


zturner added inline comments.


================
Comment at: include/llvm/Support/YAMLTraits.h:870-875
   template <typename T>
-  void mapOptional(const char *Key, T &Val, const T &Default) {
+  void mapOptional(const char *Key, T &Val,
+                   const typename std::enable_if<true, T>::type &Default) {
     EmptyContext Ctx;
     mapOptionalWithContext(Key, Val, Default, Ctx);
   }
----------------
What if you just say

```
template<typename T, typename U>
void mapOptional(const char *Key, T &Val, const U &Default) {
  EmptyContext Ctx;
  mapOptionalWithContext(Key, Val, static_cast<T>(Default), Ctx);
}
```

This way it's basically self-documenting and doesn't require `enable_if` magic.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59142/new/

https://reviews.llvm.org/D59142





More information about the llvm-commits mailing list