我有一个标题,通过使用暴露模板类和typedef,如:
namespace fancy {
struct Bar {
...
}
template<typename T>
class Foo {
...
}
using FooBar = Foo<Bar>;
}
Run Code Online (Sandbox Code Playgroud)
我想转发声明在另一个标题中FooBar使用它shared_ptr.我试过了
namespace fancy {
using FooBar;
}
Run Code Online (Sandbox Code Playgroud)
喜欢一个类或结构,但没有运气.这是可能的,如果是的话,怎么样?
我想有除了铛GCC在MinGW的,64位的Windows 7环境下,无论是使用标准库从GCC.我正在使用来自http://sourceforge.net/projects/mingwbuilds/的 gcc_x64_4.8.1_win32_seh_rev1和Qt .
我在这个环境中构建了clang 3.3,没有任何标志(只是解决了HAVE_EHTABLE_SUPPORT编译问题).
我使用qmake构建过程,项目文件还有这些行用于clang(只是发布模式):
QMAKE_CC = clang
QMAKE_CXX = clang++
QMAKE_CXXFLAGS_RELEASE += -Wno-ignored-attributes
QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1"
QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++"
QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/x86_64-w64-mingw32"
QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/x86_64-w64-mingw32/include"
Run Code Online (Sandbox Code Playgroud)
编译归结为:
C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++\bits/random.h:106:26: error:
__int128 is not supported on this target
{ typedef unsigned __int128 type; };
^
Run Code Online (Sandbox Code Playgroud)
在互联网上搜索引用了_mingw.h,但我不知道那里有什么问题:
#if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) && \
!defined(__SIZEOF_INT128__) /* clang >= 3.1 has __int128 but no size macro */
#define …Run Code Online (Sandbox Code Playgroud) 以下几个教程(例如http://boost-spirit.com/home/articles/qi-example/nabialek-trick/)我想使用Nabialek技巧来获得动态解析器.解析已经工作正常,但我没有得到运输的属性.像/sf/answers/637698071/这样的解释表明,属性应该是可能的,但不是参数.
这只是一个将字符串和数字解析为结构的小例子.这只是为了展示我的问题; 此方法应在稍后的大型系统中使用,其中真正需要动态解析器.
问题:如何使用Nabialek技巧传输属性?
我不是精神专家,所以请耐心等待.我正在使用gcc 4.8.1并提升1.54.
#define BOOST_SPIRIT_DEBUG
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/fusion/adapted/struct.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;
//------------------------------------------------------------------------------
// Data structure
struct myline {
myline()
: _n(0), _s("") {
}
myline(int n, std::string s)
: _n(n), _s(s) {
}
void set(int n, std::string s) {
_n = n;
_s = s;
}
int _n;
std::string _s;
};
BOOST_FUSION_ADAPT_STRUCT(::myline, (int, _n) (std::string, _s))
//------------------------------------------------------------------------------
// Parser grammar
template<typename It, typename …Run Code Online (Sandbox Code Playgroud) 我想使用boost文件系统读取/写入具有unicode文件名的文件,在Windows上使用boost语言环境(mingw)(最后应该是平台独立的).
这是我的代码:
#include <boost/locale.hpp>
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
namespace fs = boost::filesystem;
#include <string>
#include <iostream>
int main() {
std::locale::global(boost::locale::generator().generate(""));
fs::path::imbue(std::locale());
fs::path file("äöü.txt");
if (!fs::exists(file)) {
std::cout << "File does not exist" << std::endl;
}
fs::ofstream(file, std::ios_base::app) << "Test" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
在fs::exists真正检查与名称的文件äöü.txt.但是书面文件有名字äöü.txt.
阅读给出了同样的问题.使用fs::wofstream也没有帮助,因为这只是处理广泛的输入.
如何使用C++ 11和boost来解决这个问题?
编辑:发布错误报告:https://svn.boost.org/trac/boost/ticket/9968
澄清赏金: Qt很简单,但我想要一个只使用C++ 11和Boost,没有Qt和没有ICU的跨平台解决方案.
设置:我在C/C++环境中使用Lua.
我在磁盘上有几个lua文件.这些被读入内存,并且在运行时期间可以使用一些仅有内存的lua文件.想想一个编辑器,以及其他未保存的lua文件.
所以,我有一个list<identifier, lua_file_content>记忆.其中一些文件中包含require语句.当我尝试将所有这些文件加载到lua实例(当前通过lua_dostring)时,我得到了attempt to call global require (a nil value).
是否有可能提供一个require函数,它替换旧的函数,只使用提供的内存文件(这些文件在C端)?
是否有另一种允许require在这些文件中没有磁盘上所需文件的方法?
一个例子是只从内存加载lua stdlib而不改变它.(这实际上是我的测试用例.)
我正试图抓住新的Spirit X3(升级1.61.0).
我的机器是运行Linux的MacBook Pro(i7-4750HQ).
使用Spirit的第2版我习惯了很长的编译时间,但这感觉不对.对于表达式解析器的以下第一步,编译需要20秒.
我以为X3会更快,这个合理吗?我的代码不是最理想的吗?
编译器设置(铿锵3.8.0)
clang++ -c -pipe -std=c++14 -ftemplate-depth=512 -g -w -Wall -Wno-unused-parameter -fPIC
Run Code Online (Sandbox Code Playgroud)
码:
//#define BOOST_SPIRIT_X3_DEBUG
#include <iostream>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <string>
#include <vector>
//--------------------------------------------------------------------------------------------------
namespace client { namespace ast
{
namespace fusion = boost::fusion;
namespace x3 = boost::spirit::x3;
struct number : x3::variant<int, double> {
using base_type::base_type;
using base_type::operator=;
};
struct add_ast;
struct mult_ast;
struct block_ast;
struct function;
struct expr_ast : x3::variant<
number,
x3::forward_ast<function>,
x3::forward_ast<add_ast>,
x3::forward_ast<mult_ast>,
x3::forward_ast<block_ast>
> {
using base_type::base_type;
using …Run Code Online (Sandbox Code Playgroud) 布局引擎是neato.我希望在a到c的箭头和节点b之间有更多的空间.margin并pad没有帮助neato.这是我的图:
digraph G {
splines=true
a [pos="0.0,0.0!"];
b [pos="0.0,1.0!"];
c [pos="0.0,2.0!"];
a -> b;
a -> c;
b -> c;
}
Run Code Online (Sandbox Code Playgroud)

那可能吗?
我终于在Eclipse中运行了C++/QT项目.但是当我尝试包含例如QString时,我只在代码完成时提供了qstring.h,但是手动输入QString会起作用.
我检查了QString文件,它只包含qstring.h本身.但是有什么原因让这个文件完全没有直接在包含中使用qstring.h?
另外,是否可以在Eclipse的代码完成中获取QString?
我想生成一些格式化的输出.为此,需要一些缩进.因此,在生成期间的某个时刻,我希望获得当前位置,以便使用该数量缩进以下行.
这是一个最小的例子.请假设,我们不知道karma::lit("Some text: ")编译期间的输出有多长.实际上,这个前导文本可能由几个规则生成.
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <boost/spirit/include/karma.hpp>
using namespace std;
int main() {
vector<int> v { 0, 1, 2, 3 };
{
namespace karma = boost::spirit::karma;
karma::rule<ostream_iterator<char>, std::vector<int>() > myRule =
karma::lit("Some text: ") << (karma::int_ % karma::eol);
karma::generate(ostream_iterator<char>(cout), myRule, v);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这产生了
Some text: 0
1
2
3
Run Code Online (Sandbox Code Playgroud)
我想结果:
Some text: 0
1
2
3
Run Code Online (Sandbox Code Playgroud)
要实现这一点,需要在生成向量之前知道当前位置.那么,类似的东西qi::raw[]呢?
更新:指向此点生成输出的指针也可以.
我想跟踪unicode字符串的输入位置和输入行.
对于位置,我存储一个迭代器,以便std::distance在所需的位置开始和使用.只要输入不是unicode,这就可以正常工作.使用unicode符号,位置会移动,即ä在输入流中占用两个空格,并且位置关闭1.因此,我切换到了boost::u8_to_u32_iterator,这样可以正常工作.
对于我使用的线boost::spirit::line_pos_iterator也很好用.
我的问题是将两个概念结合起来使用行迭代器和unicode迭代器.允许在unicode字符串上使用pos和line的另一种解决方案当然也是受欢迎的.
这是unicode解析器的一个小例子; 如上所述我想另外包装迭代器,boost::spirit::line_pos_iterator但甚至不编译.
#define BOOST_SPIRIT_USE_PHOENIX_V3
#define BOOST_SPIRIT_UNICODE
#include <boost/regex/pending/unicode_iterator.hpp>
#include <boost/fusion/adapted/struct.hpp>
#include <boost/spirit/include/phoenix.hpp>
namespace phx = boost::phoenix;
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
#include <boost/spirit/repository/include/qi_iter_pos.hpp>
#include <boost/spirit/include/support_line_pos_iterator.hpp>
#include <iostream>
#include <string>
//==============================================================================
std::string to_utf8(const std::u32string& input) {
return std::string(
boost::u32_to_u8_iterator<std::u32string::const_iterator>(input.begin()),
boost::u32_to_u8_iterator<std::u32string::const_iterator>(input.end()));
}
//==============================================================================
int main() {
std::string input(u8"Hallo äöüß");
typedef boost::u8_to_u32_iterator<std::string::const_iterator> iterator_type;
iterator_type first(input.begin()), last(input.end());
qi::rule<iterator_type, std::u32string()> string_u32 = *(qi::char_ - qi::eoi);
qi::rule<iterator_type, std::string()> string =
string_u32[qi::_val …Run Code Online (Sandbox Code Playgroud) c++ ×8
boost ×4
boost-spirit ×4
unicode ×2
boost-locale ×1
c++11 ×1
clang ×1
eclipse-cdt ×1
gcc ×1
graphviz ×1
lua ×1
mingw ×1
neato ×1
qmake ×1
qt ×1