Opened 9 years ago

#8625 new Feature Requests

Add function to indicate if `swap` is no-throw

Reported by: Daryle Walker Owned by: joseph.gauterin
Milestone: Boost 1.55.0 Component: swap
Version: Boost 1.55.0 Severity: Optimization
Keywords: swap noexcept Cc:

Description

While writing a library for Boost, I found the need for this function:

    #include <utility>

    //! Detect if a type's swap (found via ADL for
    //! non-built-ins) throws.
    template < typename T, typename U = T >
    inline constexpr
    bool  is_swap_nothrow() noexcept
    {
        using std::swap;

        return noexcept( swap(std::declval<T &>(),
         std::declval<U &>()) );
    }

while writing my container's swap. You would probably use the macros for "inline," "constexpr," operator "noexcept," and the "noexcept" flag, but the function is pretty much useless unless all of those features are fully defined. The function has to be shielded from pre-C++11 compiles, of course.

Change History (0)

Note: See TracTickets for help on using tickets.