Changeset dc0fff11 in mainline


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

cpp: fixed some bugs found by the string tests

Location:
uspace/lib/cpp/include/impl
Files:
4 edited

Legend:

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

    rc20cccb rdc0fff11  
    8282    template<class Char, class Traits = char_traits<Char>,
    8383             class Allocator = allocator<Char>>
    84     class basic_istringstream;
     84    class basic_ostringstream;
    8585
    8686    template<class Char, class Traits = char_traits<Char>,
    8787             class Allocator = allocator<Char>>
    88     class basic_istringstream;
     88    class basic_stringstream;
    8989
    9090
     
    147147
    148148    // TODO: standard p. 1012, this is circular, it offers fix
    149     using streampos  = fpos<char_traits<char>::state_type>;
    150     using wstreampos = fpos<char_traits<wchar_t>::state_type>;
     149    /* using streampos  = fpos<char_traits<char>::state_type>; */
     150    /* using wstreampos = fpos<char_traits<wchar_t>::state_type>; */
     151    // Temporary workaround.
     152    using streampos =  unsigned long long;
     153    using wstreampos = unsigned long long;
     154    // TODO: This should be in ios and not here?
     155    using streamoff = long long;
    151156}
  • uspace/lib/cpp/include/impl/memory.hpp

    rc20cccb rdc0fff11  
    3131
    3232#include <internal/aux.hpp>
     33#include <utility>
    3334#include <type_traits>
    3435
  • uspace/lib/cpp/include/impl/string.hpp

    rc20cccb rdc0fff11  
    3030#define LIBCPP_STRING
    3131
    32 #include <initializer_list>
     32#include <algorithm>
    3333#include <iosfwd>
     34#include <iterator>
    3435#include <cstdio>
    3536#include <cstdlib>
    3637#include <cstring>
     38#include <memory>
     39#include <utility>
     40
     41#include <initializer_list>
    3742
    3843namespace std
     
    179184        static int compare(const char_type* s1, const char_type* s2, size_t n)
    180185        {
    181             return std::wstr_lcmp(s1, s2, n);
     186            // TODO: This function does not exits...
     187            //return std::wstr_lcmp(s1, s2, n);
     188            return 0;
    182189        }
    183190
     
    260267            using reference       = value_type&;
    261268            using const_reference = const value_type&;
    262             using pointer         = allocator_traits<allocator_type>::pointer;
    263             using const_pointer   = allocator_traits<allocator_type>::const_pointer;
     269            using pointer         = typename allocator_traits<allocator_type>::pointer;
     270            using const_pointer   = typename allocator_traits<allocator_type>::const_pointer;
    264271
    265272            using iterator               = pointer;
     
    286293                 *  capacity() = unspecified
    287294                 */
    288                 data_ = allocator_.allocate(initial_capacity_);
    289                 capacity_ = initial_capacity_;
     295                data_ = allocator_.allocate(default_capacity_);
     296                capacity_ = default_capacity_;
    290297            }
    291298
     
    315322            }
    316323
    317             basic_string(const value_type* str, size_type n, const allocator_type& alloc = allocator{})
     324            basic_string(const value_type* str, size_type n, const allocator_type& alloc = allocator_type{})
    318325                : data_{}, size_{n}, capacity_{n}, allocator_{alloc}
    319326            {
     
    321328            }
    322329
    323             basic_string(const value_type* str, const allocator_type& alloc = allocator{})
     330            basic_string(const value_type* str, const allocator_type& alloc = allocator_type{})
    324331                : data_{}, size_{}, capacity_{}, allocator_{alloc}
    325332            {
     
    327334            }
    328335
    329             basic_string(size_type n, value_type c, const allocator_type& alloc = allocator{})
     336            basic_string(size_type n, value_type c, const allocator_type& alloc = allocator_type{})
    330337                : data_{}, size_{n}, capacity_{n}, allocator_{alloc}
    331338            {
     
    338345            template<class InputIterator>
    339346            basic_string(InputIterator first, InputIterator last,
    340                          const allocator_type& alloc = allocator{})
     347                         const allocator_type& alloc = allocator_type{})
    341348                : data_{}, size_{}, capacity_{}, allocator_{alloc}
    342349            {
    343                 if constexpr (is_integral_t<InputIterator>)
     350                if constexpr (is_integral<InputIterator>::value)
    344351                { // Required by the standard.
    345352                    size_ = static_cast<size_type>(first);
     
    358365            }
    359366
    360             basic_string(initializer_list<value_type> init, const allocator_type& alloc = allocator{})
     367            basic_string(initializer_list<value_type> init, const allocator_type& alloc = allocator_type{})
    361368                : basic_string{init.begin(), init.size(), alloc}
    362369            { /* DUMMY BODY */ }
     
    629636            }
    630637
    631             basic_string& append(const basic_string& str, size_type pos
     638            basic_string& append(const basic_string& str, size_type pos,
    632639                                 size_type n = npos)
    633640            {
     
    666673            basic_string& append(InputIterator first, InputIterator last)
    667674            {
    668                 return append(basic_string(frist, last));
     675                return append(basic_string(first, last));
    669676            }
    670677
     
    704711                }
    705712                // TODO: Else throw out_of_range.
     713
     714                return *this;
    706715            }
    707716
     
    711720                resize_without_copy_(n);
    712721                traits_type::copy(begin(), str, n);
     722                size_ = n;
     723                ensure_null_terminator_();
    713724
    714725                return *this;
     
    792803                copy_backward_(begin() + pos, end(), end() + n);
    793804
    794                 auto it = position;
     805                auto it = pos;
    795806                for (size_type i = 0; i < n; ++i)
    796                     type_traits::assign(*it++, c);
     807                    traits_type::assign(*it++, c);
    797808                ensure_null_terminator_();
    798809
     
    812823            }
    813824
    814             basic_string& erase(size_type pos = 0; size_type n = npos)
     825            basic_string& erase(size_type pos = 0, size_type n = npos)
    815826            {
    816827                auto len = min(n, size_ - pos);
     
    825836            {
    826837                auto idx = static_cast<size_type>(pos - cbegin());
    827                 erase(dx, 1);
     838                erase(idx, 1);
    828839
    829840                return begin() + idx;
     
    851862            }
    852863
    853             basic_string& replace(size_type pos1, size_type n1, const basic_string& str
     864            basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
    854865                                  size_type pos2, size_type n2 = npos)
    855866            {
     
    895906                                  const value_type* str, size_type n)
    896907            {
    897                 return replace(i1 - begin(), i2 - i1, s, n);
     908                return replace(i1 - begin(), i2 - i1, str, n);
    898909            }
    899910
     
    12561267             * set capacity to 0, but that would be too cryptic.)
    12571268             */
    1258             static constexpr size_type default_capacity_{4}
     1269            static constexpr size_type default_capacity_{4};
    12591270
    12601271            void init_(const value_type* str, size_type size)
     
    12861297                 *       reserve can cause shrinking.
    12871298                 */
    1288                 if (size_ + 1 + n > capacity)
     1299                if (size_ + 1 + n > capacity_)
    12891300                    resize_with_copy_(size_, max(size_ + 1 + n, next_capacity_()));
    12901301            }
     
    13421353            void ensure_null_terminator_()
    13431354            {
    1344                 traits_type::assign(data_[size_], value_type{});
     1355                value_type c{};
     1356                traits_type::assign(data_[size_], c);
    13451357            }
    13461358
     
    13691381            }
    13701382    };
     1383
     1384    using string = basic_string<char>;
    13711385}
    13721386
  • uspace/lib/cpp/include/impl/type_traits.hpp

    rc20cccb rdc0fff11  
    153153    { /* DUMMY BODY */ };
    154154
    155     template<class T>
    156     struct is_integral: __is_integral<remove_cv_t<T>>
     155    template<class T> // TODO: use remove_cv when implemented
     156    struct is_integral: __is_integral<T>
    157157    { /* DUMMY BODY */ };
    158158
Note: See TracChangeset for help on using the changeset viewer.