Changeset 177a576 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:
98c99ba
Parents:
52d025c
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-10-25 21:00:57)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: made the public api of string actually public

File:
1 edited

Legend:

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

    r52d025c r177a576  
    251251    class basic_string
    252252    {
    253         using traits_type     = Traits;
    254         using value_type      = typename traits_type::char_type;
    255         using allocator_type  = Allocator;
    256         using size_type       = typename allocator_traits<allocator_type>::size_type;
    257         using difference_type = typename allocator_traits<allocator_type>::difference_type;
    258 
    259         using reference       = value_type&;
    260         using const_reference = const value_type&;
    261         using pointer         = allocator_traits<allocator_type>::pointer;
    262         using const_pointer   = allocator_traits<allocator_type>::const_pointer;
    263 
    264         using iterator               = pointer;
    265         using const_iterator         = const_pointer;
    266         using reverse_iterator       = std::reverse_iterator<iterator>;
    267         using const_reverse_iterator = std::reverse_iterator<const_iterator>;
    268 
    269         static constexpr size_type npos = -1;
    270 
    271         /**
    272          * 21.4.2, construct/copy/destroy:
    273          */
    274         basic_string() noexcept
    275             : basic_string(allocator_type{})
    276         { /* DUMMY BODY */ }
    277 
    278         explicit basic_string(const allocator_type& alloc);
    279 
    280         basic_string(const basic_string& other);
    281 
    282         basic_string(basic_string&& other);
    283 
    284         basic_string(const basic_string& other, size_type pos, size_type n = npos,
    285                      const allocator_type& alloc = allocator_type{});
    286 
    287         basic_string(const value_type*, size_type n, const allocator_type& alloc = allocator{});
    288 
    289         basic_string(const value_type*, const allocator_type& alloc = allocator{});
    290 
    291         basic_string(size_type n, value_type c, const allocator_type& alloc = allocator{});
    292 
    293         template<class InputIterator>
    294         basic_string(InputIterator first, InputIterator last,
    295                      const allocator_type& alloc = allocator{});
    296 
    297         basic_string(initializer_list<value_type> init, const allocator_type& alloc = allocator{});
    298 
    299         basic_string(const basic_string& other, const allocator_type& alloc);
    300 
    301         basic_string(basic_string&& other, const allocator_type& alloc);
    302 
    303         ~basic_string();
    304 
    305         basic_string& operator=(const basic_string& other);
    306 
    307         basic_string& operator=(basic_string&& other)
    308             noexcept(allocator_traits<allocator_type>::propagate_on_container_move_assignment::value ||
    309                      allocator_traits<allocator_type>::is_always_equal::value);
    310 
    311         basic_string& operator=(const value_type* other);
    312 
    313         basic_string& operator=(value_type c);
    314 
    315         basic_string& operator=(initializer_list<value_type>);
    316 
    317         /**
    318          * 21.4.3, iterators:
    319          */
    320 
    321         iterator begin() noexcept;
    322 
    323         const_iterator begin() const noexcept;
    324 
    325         iterator end() noexcept;
    326 
    327         const_iterator end() const noexcept;
    328 
    329         reverse_iterator rbegin() noexcept
    330         {
    331             return make_reverse_iterator(begin());
    332         }
    333 
    334         const_reverse_iterator rbegin() const noexcept
    335         {
    336             return make_reverse_iterator(cbegin());
    337         }
    338 
    339         reverse_iterator rend() noexcept
    340         {
    341             return make_reverse_iterator(end());
    342         }
    343 
    344         const_reverse_iterator rend() const noexcept
    345         {
    346             return make_reverse_iterator(cend());
    347         }
    348 
    349         const_iterator cbegin() const noexcept;
    350 
    351         const_iterator cend() const noexcept;
    352 
    353         const_reverse_iterator crbegin() const noexcept
    354         {
    355             return make_reverse_iterator(cbegin());
    356         }
    357 
    358         const_reverse_iterator crend() const noexcept
    359         {
    360             return make_reverse_iterator(cend());
    361         }
    362 
    363         /**
    364          * 21.4.4, capacity:
    365          */
    366 
    367         size_type size() const noexcept;
    368 
    369         size_type length() const noexcept;
    370 
    371         size_type max_size() const noexcept;
    372 
    373         void resize(size_type n, value_type c);
    374 
    375         void resize(size_type n);
    376 
    377         size_type capacity() const noexcept;
    378 
    379         void reserve(size_type res_arg = 0);
    380 
    381         void shrink_to_fit();
    382 
    383         void clear() noexcept;
    384 
    385         bool empty() const noexcept;
    386 
    387         /**
    388          * 21.4.5, element access:
    389          */
    390 
    391         const_reference operator[](size_type idx) const;
    392 
    393         reference operator[](size_type idx);
    394 
    395         const_reference at(size_type idx) const;
    396 
    397         reference at(size_type idx);
    398 
    399         const_reference front() const;
    400 
    401         reference front();
    402 
    403         const_reference back() const;
    404 
    405         reference back();
    406 
    407         /**
    408          * 21.4.6, modifiers:
    409          */
    410 
    411         basic_string& operator+=(const basic_string& str);
    412 
    413         basic_string& operator+=(const value_type* str);
    414 
    415         basic_string& operator+=(value_type c);
    416 
    417         basic_string& operator+=(initializer_list<value_type> init);
    418 
    419         basic_string& append(const basic_string& str);
    420 
    421         basic_string& append(const basic_string& str, size_type pos
    422                              size_type n = npos);
    423 
    424         basic_string& append(const value_type* str, size_type n);
    425 
    426         basic_string& append(const value_type* str);
    427 
    428         basic_string& append(size_type n, value_type c);
    429 
    430         template<class InputIterator>
    431         basic_string& append(InputIterator first, InputIterator last);
    432 
    433         basic_string& append(initializer_list<value_type> init);
    434 
    435         void push_back(value_type c);
    436 
    437         basic_string& assign(const basic_string& str);
    438 
    439         basic_string& assign(basic_string&& str);
    440 
    441         basic_string& assign(const basic_string& str, size_type pos,
    442                              size_type n = npos);
    443 
    444         basic_string& assign(const value_type* str, size_type n);
    445 
    446         basic_string& assign(const value_type* str);
    447 
    448         basic_string& assign(size_type n, value_type c);
    449 
    450         template<class InputIterator>
    451         basic_string& assign(InputIterator first, InputIterator last);
    452 
    453         basic_string& assign(initializer_list<value_type> init);
    454 
    455         basic_string& insert(size_type pos, const basic_string& str);
    456 
    457         basic_string& insert(size_type pos1, const basic_string& str,
    458                              size_type pos2, size_type n = npos);
    459 
    460         basic_string& insert(size_type pos, const value_type* str, size_type n);
    461 
    462         basic_string& insert(size_type pos, const value_type* str);
    463 
    464         basic_string& insert(size_type pos, size_type n, value_type c);
    465 
    466         iterator insert(const_iterator pos, value_type c);
    467 
    468         iterator insert(const_iterator pos, size_type n, value_type c);
    469 
    470         template<class InputIterator>
    471         iterator insert(const_iterator pos, InputIterator first,
    472                         InputIterator last);
    473 
    474         iterator insert(const_iterator pos, initializer_list<value_type>);
    475 
    476         basic_string& erase(size_type pos = 0; size_type n = npos);
    477 
    478         iterator erase(const_iterator pos);
    479 
    480         iterator erase(const_iterator pos, const_iterator last);
    481 
    482         void pop_back();
    483 
    484         basic_string& replace(size_type pos, size_type n, const basic_string& str);
    485 
    486         basic_string& replace(size_type pos1, size_type n1, const basic_string& str
    487                               size_type pos2, size_type n2);
    488 
    489         basic_string& replace(size_type pos, size_type n1, const value_type* str,
    490                               size_type n2);
    491 
    492         basic_string& replace(size_type pos, size_type n, const value_type* str);
    493 
    494         basic_string& replace(size_type pos, size_type n1, size_type n2,
    495                               value_type c);
    496 
    497         basic_string& replace(const_iterator i1, const_iterator i2,
    498                               const basic_string& str);
    499 
    500         basic_string& replace(const_iterator i1, const_iterator i2,
    501                               const value_type* str, size_type n);
    502 
    503         basic_string& replace(const_iterator i1, const_iterator i2,
    504                               const value_type* str);
    505 
    506         basic_string& replace(const_iterator i1, const_iterator i2,
    507                               value_type c);
    508 
    509         template<class InputIterator>
    510         basic_string& replace(const_iterator i1, const_iterator i2,
    511                               InputIterator j1, InputIterator j2);
    512 
    513         basic_string& replace(const_iterator i1, const_iterator i2,
    514                               initializer_list<value_type> init);
    515 
    516         size_type copy(value_type* str, size_type n, size_type pos = 0) const;
    517 
    518         void swap(basic_string& other)
    519             noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
    520                      allocator_traits<allocator_type>::is_always_equal);
    521 
    522         /**
    523          * 21.4.7, string operations:
    524          */
    525 
    526         const value_type* c_str() const noexcept;
    527 
    528         const value_type* data() const noexcept;
    529 
    530         allocator_type get_allocator() const noexcept;
    531 
    532         size_type find(const basic_string& str, size_type pos = 0) const noexcept;
    533 
    534         size_type find(const value_type* str, size_type pos, size_type n) const;
    535 
    536         size_type find(const value_type* str, size_type pos = 0) const;
    537 
    538         size_type find(value_type c, size_type pos = 0) const;
    539 
    540         size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
    541 
    542         size_type rfind(const value_type* str, size_type pos, size_type n) const;
    543 
    544         size_type rfind(const value_type* str, size_type pos = npos) const;
    545 
    546         size_type rfind(value_type c, size_type pos = npos) const;
    547 
    548         size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
    549 
    550         size_type find_first_of(const value_type* str, size_type pos, size_type n) const;
    551 
    552         size_type find_first_of(const value_type* str, size_type pos = 0) const;
    553 
    554         size_type find_first_of(value_type c, size_type pos = 0) const;
    555 
    556         size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
    557 
    558         size_type find_last_of(const value_type* str, size_type pos, size_type n) const;
    559 
    560         size_type find_last_of(const value_type* str, size_type pos = npos) const;
    561 
    562         size_type find_last_of(value_type c, size_type pos = npos) const;
    563 
    564         size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
    565 
    566         size_type find_first_not_of(const value_type* str, size_type pos, size_type n) const;
    567 
    568         size_type find_first_not_of(const value_type* str, size_type pos = 0) const;
    569 
    570         size_type find_first_not_of(value_type c, size_type pos = 0) const;
    571 
    572         size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
    573 
    574         size_type find_last_not_of(const value_type* str, size_type pos, size_type n) const;
    575 
    576         size_type find_last_not_of(const value_type* str, size_type pos = npos) const;
    577 
    578         size_type find_last_not_of(value_type c, size_type pos = npos) const;
    579 
    580         basic_string substr(size_type pos = 0, size_type n = npos) const;
    581 
    582         int compare(const basic_string& other) const noexcept;
    583 
    584         int compare(size_type pos, size_type n, const basic_string& other) const;
    585 
    586         int compare(size_type pos1, size_type n1, const basic_string& other,
    587                     size_type pos2, size_type n2 = npos) const;
    588 
    589         int compare(const value_type* other) const;
    590 
    591         int compare(size_type pos, size_type n, const value_type* other) const;
    592 
    593         int compare(size_type pos1, size_type n1,
    594                     const value_type* other, size_type n2) const;
     253        public:
     254            using traits_type     = Traits;
     255            using value_type      = typename traits_type::char_type;
     256            using allocator_type  = Allocator;
     257            using size_type       = typename allocator_traits<allocator_type>::size_type;
     258            using difference_type = typename allocator_traits<allocator_type>::difference_type;
     259
     260            using reference       = value_type&;
     261            using const_reference = const value_type&;
     262            using pointer         = allocator_traits<allocator_type>::pointer;
     263            using const_pointer   = allocator_traits<allocator_type>::const_pointer;
     264
     265            using iterator               = pointer;
     266            using const_iterator         = const_pointer;
     267            using reverse_iterator       = std::reverse_iterator<iterator>;
     268            using const_reverse_iterator = std::reverse_iterator<const_iterator>;
     269
     270            static constexpr size_type npos = -1;
     271
     272            /**
     273             * 21.4.2, construct/copy/destroy:
     274             */
     275            basic_string() noexcept
     276                : basic_string(allocator_type{})
     277            { /* DUMMY BODY */ }
     278
     279            explicit basic_string(const allocator_type& alloc);
     280
     281            basic_string(const basic_string& other);
     282
     283            basic_string(basic_string&& other);
     284
     285            basic_string(const basic_string& other, size_type pos, size_type n = npos,
     286                         const allocator_type& alloc = allocator_type{});
     287
     288            basic_string(const value_type*, size_type n, const allocator_type& alloc = allocator{});
     289
     290            basic_string(const value_type*, const allocator_type& alloc = allocator{});
     291
     292            basic_string(size_type n, value_type c, const allocator_type& alloc = allocator{});
     293
     294            template<class InputIterator>
     295            basic_string(InputIterator first, InputIterator last,
     296                         const allocator_type& alloc = allocator{});
     297
     298            basic_string(initializer_list<value_type> init, const allocator_type& alloc = allocator{});
     299
     300            basic_string(const basic_string& other, const allocator_type& alloc);
     301
     302            basic_string(basic_string&& other, const allocator_type& alloc);
     303
     304            ~basic_string();
     305
     306            basic_string& operator=(const basic_string& other);
     307
     308            basic_string& operator=(basic_string&& other)
     309                noexcept(allocator_traits<allocator_type>::propagate_on_container_move_assignment::value ||
     310                         allocator_traits<allocator_type>::is_always_equal::value);
     311
     312            basic_string& operator=(const value_type* other);
     313
     314            basic_string& operator=(value_type c);
     315
     316            basic_string& operator=(initializer_list<value_type>);
     317
     318            /**
     319             * 21.4.3, iterators:
     320             */
     321
     322            iterator begin() noexcept;
     323
     324            const_iterator begin() const noexcept;
     325
     326            iterator end() noexcept;
     327
     328            const_iterator end() const noexcept;
     329
     330            reverse_iterator rbegin() noexcept
     331            {
     332                return make_reverse_iterator(begin());
     333            }
     334
     335            const_reverse_iterator rbegin() const noexcept
     336            {
     337                return make_reverse_iterator(cbegin());
     338            }
     339
     340            reverse_iterator rend() noexcept
     341            {
     342                return make_reverse_iterator(end());
     343            }
     344
     345            const_reverse_iterator rend() const noexcept
     346            {
     347                return make_reverse_iterator(cend());
     348            }
     349
     350            const_iterator cbegin() const noexcept;
     351
     352            const_iterator cend() const noexcept;
     353
     354            const_reverse_iterator crbegin() const noexcept
     355            {
     356                return make_reverse_iterator(cbegin());
     357            }
     358
     359            const_reverse_iterator crend() const noexcept
     360            {
     361                return make_reverse_iterator(cend());
     362            }
     363
     364            /**
     365             * 21.4.4, capacity:
     366             */
     367
     368            size_type size() const noexcept;
     369
     370            size_type length() const noexcept;
     371
     372            size_type max_size() const noexcept;
     373
     374            void resize(size_type n, value_type c);
     375
     376            void resize(size_type n);
     377
     378            size_type capacity() const noexcept;
     379
     380            void reserve(size_type res_arg = 0);
     381
     382            void shrink_to_fit();
     383
     384            void clear() noexcept;
     385
     386            bool empty() const noexcept;
     387
     388            /**
     389             * 21.4.5, element access:
     390             */
     391
     392            const_reference operator[](size_type idx) const;
     393
     394            reference operator[](size_type idx);
     395
     396            const_reference at(size_type idx) const;
     397
     398            reference at(size_type idx);
     399
     400            const_reference front() const;
     401
     402            reference front();
     403
     404            const_reference back() const;
     405
     406            reference back();
     407
     408            /**
     409             * 21.4.6, modifiers:
     410             */
     411
     412            basic_string& operator+=(const basic_string& str);
     413
     414            basic_string& operator+=(const value_type* str);
     415
     416            basic_string& operator+=(value_type c);
     417
     418            basic_string& operator+=(initializer_list<value_type> init);
     419
     420            basic_string& append(const basic_string& str);
     421
     422            basic_string& append(const basic_string& str, size_type pos
     423                                 size_type n = npos);
     424
     425            basic_string& append(const value_type* str, size_type n);
     426
     427            basic_string& append(const value_type* str);
     428
     429            basic_string& append(size_type n, value_type c);
     430
     431            template<class InputIterator>
     432            basic_string& append(InputIterator first, InputIterator last);
     433
     434            basic_string& append(initializer_list<value_type> init);
     435
     436            void push_back(value_type c);
     437
     438            basic_string& assign(const basic_string& str);
     439
     440            basic_string& assign(basic_string&& str);
     441
     442            basic_string& assign(const basic_string& str, size_type pos,
     443                                 size_type n = npos);
     444
     445            basic_string& assign(const value_type* str, size_type n);
     446
     447            basic_string& assign(const value_type* str);
     448
     449            basic_string& assign(size_type n, value_type c);
     450
     451            template<class InputIterator>
     452            basic_string& assign(InputIterator first, InputIterator last);
     453
     454            basic_string& assign(initializer_list<value_type> init);
     455
     456            basic_string& insert(size_type pos, const basic_string& str);
     457
     458            basic_string& insert(size_type pos1, const basic_string& str,
     459                                 size_type pos2, size_type n = npos);
     460
     461            basic_string& insert(size_type pos, const value_type* str, size_type n);
     462
     463            basic_string& insert(size_type pos, const value_type* str);
     464
     465            basic_string& insert(size_type pos, size_type n, value_type c);
     466
     467            iterator insert(const_iterator pos, value_type c);
     468
     469            iterator insert(const_iterator pos, size_type n, value_type c);
     470
     471            template<class InputIterator>
     472            iterator insert(const_iterator pos, InputIterator first,
     473                            InputIterator last);
     474
     475            iterator insert(const_iterator pos, initializer_list<value_type>);
     476
     477            basic_string& erase(size_type pos = 0; size_type n = npos);
     478
     479            iterator erase(const_iterator pos);
     480
     481            iterator erase(const_iterator pos, const_iterator last);
     482
     483            void pop_back();
     484
     485            basic_string& replace(size_type pos, size_type n, const basic_string& str);
     486
     487            basic_string& replace(size_type pos1, size_type n1, const basic_string& str
     488                                  size_type pos2, size_type n2);
     489
     490            basic_string& replace(size_type pos, size_type n1, const value_type* str,
     491                                  size_type n2);
     492
     493            basic_string& replace(size_type pos, size_type n, const value_type* str);
     494
     495            basic_string& replace(size_type pos, size_type n1, size_type n2,
     496                                  value_type c);
     497
     498            basic_string& replace(const_iterator i1, const_iterator i2,
     499                                  const basic_string& str);
     500
     501            basic_string& replace(const_iterator i1, const_iterator i2,
     502                                  const value_type* str, size_type n);
     503
     504            basic_string& replace(const_iterator i1, const_iterator i2,
     505                                  const value_type* str);
     506
     507            basic_string& replace(const_iterator i1, const_iterator i2,
     508                                  value_type c);
     509
     510            template<class InputIterator>
     511            basic_string& replace(const_iterator i1, const_iterator i2,
     512                                  InputIterator j1, InputIterator j2);
     513
     514            basic_string& replace(const_iterator i1, const_iterator i2,
     515                                  initializer_list<value_type> init);
     516
     517            size_type copy(value_type* str, size_type n, size_type pos = 0) const;
     518
     519            void swap(basic_string& other)
     520                noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
     521                         allocator_traits<allocator_type>::is_always_equal);
     522
     523            /**
     524             * 21.4.7, string operations:
     525             */
     526
     527            const value_type* c_str() const noexcept;
     528
     529            const value_type* data() const noexcept;
     530
     531            allocator_type get_allocator() const noexcept;
     532
     533            size_type find(const basic_string& str, size_type pos = 0) const noexcept;
     534
     535            size_type find(const value_type* str, size_type pos, size_type n) const;
     536
     537            size_type find(const value_type* str, size_type pos = 0) const;
     538
     539            size_type find(value_type c, size_type pos = 0) const;
     540
     541            size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
     542
     543            size_type rfind(const value_type* str, size_type pos, size_type n) const;
     544
     545            size_type rfind(const value_type* str, size_type pos = npos) const;
     546
     547            size_type rfind(value_type c, size_type pos = npos) const;
     548
     549            size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
     550
     551            size_type find_first_of(const value_type* str, size_type pos, size_type n) const;
     552
     553            size_type find_first_of(const value_type* str, size_type pos = 0) const;
     554
     555            size_type find_first_of(value_type c, size_type pos = 0) const;
     556
     557            size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
     558
     559            size_type find_last_of(const value_type* str, size_type pos, size_type n) const;
     560
     561            size_type find_last_of(const value_type* str, size_type pos = npos) const;
     562
     563            size_type find_last_of(value_type c, size_type pos = npos) const;
     564
     565            size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
     566
     567            size_type find_first_not_of(const value_type* str, size_type pos, size_type n) const;
     568
     569            size_type find_first_not_of(const value_type* str, size_type pos = 0) const;
     570
     571            size_type find_first_not_of(value_type c, size_type pos = 0) const;
     572
     573            size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
     574
     575            size_type find_last_not_of(const value_type* str, size_type pos, size_type n) const;
     576
     577            size_type find_last_not_of(const value_type* str, size_type pos = npos) const;
     578
     579            size_type find_last_not_of(value_type c, size_type pos = npos) const;
     580
     581            basic_string substr(size_type pos = 0, size_type n = npos) const;
     582
     583            int compare(const basic_string& other) const noexcept;
     584
     585            int compare(size_type pos, size_type n, const basic_string& other) const;
     586
     587            int compare(size_type pos1, size_type n1, const basic_string& other,
     588                        size_type pos2, size_type n2 = npos) const;
     589
     590            int compare(const value_type* other) const;
     591
     592            int compare(size_type pos, size_type n, const value_type* other) const;
     593
     594            int compare(size_type pos1, size_type n1,
     595                        const value_type* other, size_type n2) const;
    595596    };
    596597}
Note: See TracChangeset for help on using the changeset viewer.