How does std work:is_convertible<u (*)[]="" (*)[],="" t="">::value?</u>



  • I was digging into chromium-a files, and I ran into it. https://source.chromium.org/chromium/chromium/src/+/master:base/containers/checked_iterators.h;l=57;bpv=0;bpt=1

    Here's a piece of what's going on. some magic.

      template <
          typename U,
          std::enable_if_t<std::is_convertible<U (*)[], T (*)[]>::value>* = nullptr>
      constexpr CheckedContiguousIterator(const CheckedContiguousIterator<U>& other)
          : start_(other.start_), current_(other.current_), end_(other.end_) {
        // We explicitly don't delegate to the 3-argument constructor here. Its
        // CHECKs would be redundant, since we expect |other| to maintain its own
        // invariant. However, DCHECKs never hurt anybody. Presumably.
        DCHECK_LE(other.start_, other.current_);
        DCHECK_LE(other.current_, other.end_);
      }
    

    Please explain what's going on in this line:

    template <typename U, std::enable_if_t<std::is_convertible<U (*)[], T (*)[]>::value>* = nullptr>
    
    • Why "= nullptr"?
    • What is "U(*)[" and how does it work?

  • QA Engineer

    Why "= nullptr"?

    Nothing. I mean, it could be written differently without changing the essence.

    'std:enable_if_t' is used as a template for SFINAE if the setting of the first parameter for failure, 'std:enable_if_t' is not compromised and the function is discharged. In the case of a good setup, enable_if_t Yes typedef for his second chablon parameter, which by default void. To ensure that there are no unnecessary templates, a parameter formed enable_if_t They're default. There are many options:

    • enable_if_t<..., void>* = nullptr - a longer recording of what is in the reference example
    • enable_if_t<..., int> = 0 - a template int
    • class = enable_if_t<...> - A template type version

    What is "U(*)[" and how does it work?

    An index to the mass. An explanation in the commentary.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2