コード例 #1
0
ファイル: optimize.hpp プロジェクト: NOMORECOFFEE/hpx
        void resize_string(std::size_t reserve_prepend_, std::size_t reserve_append_) {
            if ( is_string_set() ) {
                std::size_t to_add = reserve_prepend_ + reserve_append_ - m_reserve_prepend - m_reserve_append ;
                std::size_t new_size = m_str.size() + to_add;
                
                // I'm creating a new string instead of resizing the existing one
                // this is because the new string could be of lower size
                string_type new_str(reserve_prepend_, 0);
                std::size_t used_size = m_str.size() - m_reserve_prepend - m_reserve_append;
                new_str.insert( new_str.end(), m_str.begin() +
                        static_cast<typename string_type::difference_type>(m_reserve_prepend), m_str.begin() +
                        static_cast<typename string_type::difference_type>(m_reserve_prepend + used_size));

                BOOST_ASSERT(new_size == reserve_prepend_ + used_size + reserve_append_);

                new_str.resize( new_size, 0);
                std::swap(new_str, m_str);
            }

            m_reserve_prepend = reserve_prepend_;
            m_reserve_append = reserve_append_;
        }
コード例 #2
0
ファイル: optimize.hpp プロジェクト: cargabsj175/bombono-dvd
        void resize_string(int reserve_prepend, int reserve_append) {
            BOOST_ASSERT( reserve_prepend >= 0 && reserve_append >= 0);

            if ( is_string_set() ) {
                int to_add = reserve_prepend + reserve_append - m_reserve_prepend - m_reserve_append ;
                int new_size = (int)m_str.size() + to_add;
                if ( new_size < 0)
                    new_size = 0;
                // I'm creating a new string instead of resizing the existing one
                // this is because the new string could be of lower size
                string_type new_str(reserve_prepend, 0);
                int used_size = (int)m_str.size() - m_reserve_prepend - m_reserve_append;
                new_str.insert( new_str.end(), m_str.begin() + m_reserve_prepend, m_str.begin() + m_reserve_prepend + used_size);

                BOOST_ASSERT(new_size == reserve_prepend + used_size + reserve_append);

                new_str.resize( new_size, 0);
                std::swap(new_str, m_str);
            }

            m_reserve_prepend = reserve_prepend;
            m_reserve_append = reserve_append;
        }