Changeset 614b07e in mainline


Ignore:
Timestamp:
2018-07-05T21:41:23Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bdc981b
Parents:
c866a83
git-author:
Dzejrou <dzejrou@…> (2018-05-05 17:19:00)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
Message:

cpp: moved addressof to an internal header to avoid circular dependencies, added temporary buffers and raw storage iterator

Location:
uspace/lib/cpp/include
Files:
1 added
3 edited

Legend:

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

    rc866a83 r614b07e  
    3232#include <cstdlib>
    3333#include <initializer_list>
     34#include <internal/memory/addressof.hpp>
    3435#include <iosfwd>
    35 #include <memory>
    3636#include <type_traits>
    3737#include <utility>
  • uspace/lib/cpp/include/impl/memory.hpp

    rc866a83 r614b07e  
    3131
    3232#include <internal/aux.hpp>
     33#include <internal/memory/addressof.hpp>
     34#include <iterator>
    3335#include <new>
    3436#include <type_traits>
     
    398400     */
    399401
    400     // TODO: implement
     402    template<class OutputIterator, class T>
     403    class raw_storage_iterator: public iterator<output_iterator_tag, void, void, void, void>
     404    {
     405        public:
     406            explicit raw_storage_iterator(OutputIterator it)
     407                : it_{it}
     408            { /* DUMMY BODY */ }
     409
     410            raw_storage_iterator& operator*()
     411            {
     412                return *this;
     413            }
     414
     415            raw_storage_iterator& operator=(const T& element)
     416            {
     417                new(it_) T{element};
     418
     419                return *this;
     420            }
     421
     422            raw_storage_iterator& operator++()
     423            {
     424                ++it_;
     425
     426                return *this;
     427            }
     428
     429            raw_storage_iterator operator++(int)
     430            {
     431                return raw_storage_iterator{it_++};
     432            }
     433
     434        private:
     435            OutputIterator it_;
     436    };
    401437
    402438    /**
     
    404440     */
    405441
    406     // TODO: implement
     442    template<class T>
     443    pair<T*, ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept
     444    {
     445        T* res{};
     446
     447        while (n > 0)
     448        {
     449            res = (T*)malloc(n * sizeof(T));
     450
     451            if (res)
     452                return make_pair(res, n);
     453
     454            --n;
     455        }
     456
     457        return make_pair(nullptr, ptrdiff_t{});
     458    }
     459
     460    template<class T>
     461    void return_temporary_buffer(T* ptr)
     462    {
     463        free(ptr);
     464    }
    407465
    408466    /**
    409467     * 20.7.12, specialized algorithms:
    410468     */
    411 
    412     template<class T>
    413     T* addressof(T& x) noexcept
    414     {
    415         return reinterpret_cast<T*>(
    416             &const_cast<char&>(
    417                 reinterpret_cast<const volatile char&>(x)
    418         ));
    419     }
    420469
    421470    template<class Iterator>
  • uspace/lib/cpp/include/memory

    rc866a83 r614b07e  
    2828
    2929#include <impl/memory.hpp>
     30#include <internal/memory/addressof.hpp>
Note: See TracChangeset for help on using the changeset viewer.