Changeset 5abc7fd in mainline


Ignore:
Timestamp:
2018-07-05T21:41:17Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6d4e0d9
Parents:
5fb070d
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-10-13 18:37:15)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:17)
Message:

cpp: added exchange and partial swap definitions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/utility.hpp

    r5fb070d r5abc7fd  
    6161    }
    6262
    63     // TODO: swap
    64     // TODO: exchange
     63    /**
     64     * 20.2.2, swap:
     65     */
     66
     67    template<class T>
     68    void swap(T& x, T& y)
     69        noexcept(is_nothrow_move_constructible<T>::value &&
     70                 is_nothrow_move_assignable<T>::value)
     71    {
     72        T tmp{std::move(x)};
     73        x = std::move(y);
     74        y = std::move(tmp);
     75    }
     76
     77    template<class T, size_t N>
     78    void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)))
     79    {
     80        // TODO: Use swap_ranges(a, a + N, b); when implemented.
     81    }
     82
     83    /**
     84     * 20.2.3, exchange:
     85     */
     86
     87    template<class T, class U = T>
     88    T exchange(T& obj, U&& new_val)
     89    {
     90        T old_val = std::move(obj);
     91        obj = std::forward<U>(new_val);
     92
     93        return old_val;
     94    }
    6595
    6696    /**
Note: See TracChangeset for help on using the changeset viewer.