簡體   English   中英

提升語言環境不完整的類型boundary_indexing <char32_t>

[英]boost locale incomplete type boundary_indexing<char32_t>

我首先將utf-8字符串轉換為utf-32,然后我希望將唯一的單詞與其位置進行映射。 我從提升語言環境開始。

#include <iostream>
#include <string>
#include <chrono>
#include <boost/shared_ptr.hpp>
#include <map>
#include <list>
#include <boost/locale.hpp>

typedef std::u32string string_type;
typedef std::pair<unsigned long, unsigned long> range_type;
typedef std::map<std::string, std::list<range_type>> wordref_type;

struct parser{
    /**
     * returns a map of "words" with its positions list
     */
    static wordref_type parse(string_type::const_iterator b, string_type::const_iterator e){
        wordref_type wordrefs;
        range_type sentence;

        boost::locale::boundary::segment_index<string_type::const_iterator> index(boost::locale::boundary::word, b, e);
        //TODO: iterate index
        return wordrefs;
    }
};

int main(int argc, char** argv){
    std::string input_str = "Some UTF-8 texts";
    string_type buffer = boost::locale::conv::utf_to_utf<string_type::value_type>(input_str); // convert utf-8 to utf-32
    wordref_type wordrefs = parser::parse(buffer.cbegin(), buffer.cend());
    return 0;
}

它抱怨invalid use of incomplete type 'const class boost::locale::boundary::boundary_indexing<char32_t>' 怎么了 ? 我有Ideone

In file included from /usr/include/boost/locale/boundary.hpp:15:0,
                 from /usr/include/boost/locale.hpp:11,
                 from prog.cpp:7:
/usr/include/boost/locale/boundary/index.hpp: In instantiation of ‘static boost::locale::boundary::index_type boost::locale::boundary::details::mapping_traits<IteratorType, std::random_access_iterator_tag>::map(boost::locale::boundary::boundary_type, IteratorType, IteratorType, const std::locale&) [with IteratorType = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >; boost::locale::boundary::index_type = std::vector<boost::locale::boundary::break_info>]’:
/usr/include/boost/locale/boundary/index.hpp:126:83:   required from ‘boost::locale::boundary::details::mapping<BaseIterator>::mapping(boost::locale::boundary::boundary_type, boost::locale::boundary::details::mapping<BaseIterator>::base_iterator, boost::locale::boundary::details::mapping<BaseIterator>::base_iterator, const std::locale&) [with BaseIterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >; boost::locale::boundary::details::mapping<BaseIterator>::base_iterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >]’
/usr/include/boost/locale/boundary/index.hpp:631:43:   required from ‘boost::locale::boundary::segment_index<BaseIterator>::segment_index(boost::locale::boundary::boundary_type, boost::locale::boundary::segment_index<BaseIterator>::base_iterator, boost::locale::boundary::segment_index<BaseIterator>::base_iterator, const std::locale&) [with BaseIterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >; boost::locale::boundary::segment_index<BaseIterator>::base_iterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >]’
prog.cpp:21:118:   required from here
/usr/include/boost/locale/boundary/index.hpp:98:93: error: invalid use of incomplete type ‘const class boost::locale::boundary::boundary_indexing<char32_t>’
                             index_type tmp=std::use_facet<boundary_indexing<char_type> >(l).map(t,begin,end);
                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/boost/locale/boundary.hpp:12:0,
                 from /usr/include/boost/locale.hpp:11,
                 from prog.cpp:7:
/usr/include/boost/locale/boundary/facets.hpp:90:19: note: declaration of ‘class boost::locale::boundary::boundary_indexing<char32_t>’
             class boundary_indexing;
                   ^~~~~~~~~~~~~~~~~
In file included from /usr/include/boost/locale/boundary.hpp:15:0,
                 from /usr/include/boost/locale.hpp:11,
                 from prog.cpp:7:
/usr/include/boost/locale/boundary/index.hpp:103:95: error: invalid use of incomplete type ‘const class boost::locale::boundary::boundary_indexing<char32_t>’
                             index_type tmp = std::use_facet<boundary_indexing<char_type> >(l).map(t,str.c_str(),str.c_str()+str.size());
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/boost/locale/boundary.hpp:12:0,
                 from /usr/include/boost/locale.hpp:11,
                 from prog.cpp:7:
/usr/include/boost/locale/boundary/facets.hpp:90:19: note: declaration of ‘class boost::locale::boundary::boundary_indexing<char32_t>’
             class boundary_indexing;
                   ^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/locale_classes.h:850:0,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/ostream:38,
                 from /usr/include/c++/6/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/6/bits/locale_classes.tcc: In instantiation of ‘const _Facet& std::use_facet(const std::locale&) [with _Facet = boost::locale::boundary::boundary_indexing<char32_t>]’:
/usr/include/boost/locale/boundary/index.hpp:98:89:   required from ‘static boost::locale::boundary::index_type boost::locale::boundary::details::mapping_traits<IteratorType, std::random_access_iterator_tag>::map(boost::locale::boundary::boundary_type, IteratorType, IteratorType, const std::locale&) [with IteratorType = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >; boost::locale::boundary::index_type = std::vector<boost::locale::boundary::break_info>]’
/usr/include/boost/locale/boundary/index.hpp:126:83:   required from ‘boost::locale::boundary::details::mapping<BaseIterator>::mapping(boost::locale::boundary::boundary_type, boost::locale::boundary::details::mapping<BaseIterator>::base_iterator, boost::locale::boundary::details::mapping<BaseIterator>::base_iterator, const std::locale&) [with BaseIterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >; boost::locale::boundary::details::mapping<BaseIterator>::base_iterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >]’
/usr/include/boost/locale/boundary/index.hpp:631:43:   required from ‘boost::locale::boundary::segment_index<BaseIterator>::segment_index(boost::locale::boundary::boundary_type, boost::locale::boundary::segment_index<BaseIterator>::base_iterator, boost::locale::boundary::segment_index<BaseIterator>::base_iterator, const std::locale&) [with BaseIterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >; boost::locale::boundary::segment_index<BaseIterator>::base_iterator = __gnu_cxx::__normal_iterator<const char32_t*, std::__cxx11::basic_string<char32_t> >]’
prog.cpp:21:118:   required from here
/usr/include/c++/6/bits/locale_classes.tcc:134:37: error: incomplete type ‘boost::locale::boundary::boundary_indexing<char32_t>’ used in nested name specifier
       const size_t __i = _Facet::id._M_id();


                ~~~~~~~~~~~^~~~~

您需要使用BOOST_LOCALE_ENABLE_CHAR32_T編譯boost以包括boundary_indexing<char32_t>但是...

C ++ 11 char16_t / char32_t支持的狀態

C ++ 11 char16_tchar32_t的支持是試驗性的, 大多數情況下不起作用,並且不打算用於當前最新編譯器(GCC-4.5,MSVC10)的生產中 ,直到主要編譯器的缺陷得以修復。

[....]

如果要使用C ++ 11 char16_t和char32_t支持構建或測試Boost.Locale,則應在構建過程cxxflags="-DBOOST_LOCALE_ENABLE_CHAR32_T -DBOOST_LOCALE_ENABLE_CHAR16_T"傳遞給b2,並在使用BOOST_LOCALE_e和BOOST_LOCALE_ENABLE_CHAR32_T時定義BOOST_LOCALE_ENABLE_CHAR32_T和BOOST_LOCALE_e。

[強調我的]

http://www.boost.org/doc/libs/1_66_0/libs/locale/doc/html/facets_8hpp_source.html

#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
template<>
class BOOST_LOCALE_DECL boundary_indexing<char32_t> : public std::locale::facet {

它抱怨不完整類型'const class boost :: locale :: boundary :: boundary_indexing'的無效使用怎么了?

不支持char32_t 采用

#define BOOST_LOCALE_ENABLE_CHAR32_T

但是,您還需要在構建庫時啟用它

對C ++ 0x char16_t和char32_t字符串和流的實驗支持。

進一步查看: http : //www.boost.org/doc/libs/1_64_0/libs/locale/doc/html/status_of_cpp0x_characters_support.html

如果要使用C ++ 11 char16_t和char32_t支持構建或測試Boost.Locale,則應在構建過程中將cxxflags =“-DBOOST_LOCALE_ENABLE_CHAR32_T -DBOOST_LOCALE_ENABLE_CHAR16_T”傳遞給b2,並在使用BOOST_LOCALE_e和BOOST_LOCALE_e時定義BOOST_LOCALE_ENABLE_CHAR32_T和BOOST_LOCALE_e。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM