Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for C++ 17. #24

Open
LYP951018 opened this issue Jun 25, 2016 · 0 comments
Open

Update for C++ 17. #24

LYP951018 opened this issue Jun 25, 2016 · 0 comments
Assignees

Comments

@LYP951018
Copy link

LYP951018 commented Jun 25, 2016

  • void_t idiom[1]
template<typename T, typename = void>
struct HasReference : std::false_type {};
template<typename T>
struct HasReference<T, std::void_t<typename T::reference>> : std::true_type {};

[1] CppCon 2014: Walter E. Brown "Modern Template Metaprogramming: A Compendium, Part II"

  • type_traits_v
    借助于 C++ 14 的 variable templates:
    is_same_v ...
  • constexpr if
    可以干掉 Tag Dispatch:
template<typename Iterator>
Iterator next(Iterator iter, std::ptrdiff_t dist)
{
        using category = typename std::iterator_traits<Iterator>::iterator_category;
        constexpr if(std::is_base_of_v<std::random_access_iterator_tag, category>)
            return iter + dist;
        else constexpr if(std::is_base_of_v<std::input_iterator_tag, category>)
        {
            for(std::ptrdiff_t i = 0; i < dist; ++i)
                ++iter;
            return iter;
        }
 }
  • std::conjunction/std::disjunction/std::negation
template<typename... TArgs, typename... UArgs>
struct BeExplicit: std::conjunction<std::is_constructible<TArgs, UArgs>..., std::disjunction<std::negation<std::is_convertible<UArgs, TArgs>>...>> {};
template <auto x> 
constexpr auto constant = x;

constant<true> c1; 
constant<2> c2;
std::tuple t{1, 2.0, "haha"s}; //std::tuple<int, double, std::string>
std::unique_ptr handle{::CreateFile(xxx), [](auto h) noexcept { ::CloseHandle(h); }};
@wuye9036 wuye9036 self-assigned this Jul 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants