小编eci*_*eci的帖子

Boost mpl转换序列"真实"类型

请参阅boost mpl转换文档中的以下代码:

typedef vector<char,short,int,long,float,double> types;
typedef vector<char*,short*,int*,long*,float*,double*> pointers;
typedef transform< types,boost::add_pointer<_1> >::type result;
BOOST_STATIC_ASSERT(( equal<result,pointers>::value ));
Run Code Online (Sandbox Code Playgroud)

我想了解类型系统boost::mpl和"它是如何工作的".据我所知,mpl::equal只是比较以下两个序列的元素,而不是整个序列类型本身.我不明白为什么以下失败:

BOOST_STATIC_ASSERT(( std::is_same<result,pointers>::value )); //< assert fails
Run Code Online (Sandbox Code Playgroud)

为什么结果类型与"指针"类型不完全相同?我假设这是某种程度上因为mpl正在执行变换懒惰或结果只是一个序列而不再是一个向量?有可能以某种方式迫使mpl不再懒惰并获得100%相同的类型(我可以用这个结果自己写一个转换函数,但我想知道如何在mpl中做到这一点)?

我已经尝试过一些事情,例如将结果插入到新的向量中但没有成功:

BOOST_STATIC_ASSERT(( std::is_same<
  mpl::insert_range< mpl::vector<>, mpl::begin<mpl::vector<> >::type,
  result >::type, pointers >::value )); //< assert fails too
Run Code Online (Sandbox Code Playgroud)

另外,我尝试在转换函数中使用back_insert,它也失败了:

typedef transform< types,boost::add_pointer<_1>,
  mpl::back_inserter< mpl::vector< > > >::type result_new;
BOOST_STATIC_ASSERT(( std::is_same<result_new,pointers>::value )); //< fails...
Run Code Online (Sandbox Code Playgroud)

阅读"文档"并没有帮助我.那么,是否有可能通过mpl变换(或任何其他变换序列函数)获得100%相同的类型?这种类型的结果是什么?

result
Run Code Online (Sandbox Code Playgroud)

"实际上"当它不是带指针的is_same时?

c++ templates boost boost-mpl

4
推荐指数
1
解决办法
1104
查看次数

Emacs xml模式缩进,带有选项卡

我拼命尝试使用制表符而不是空格来制作我的emacs xml(sgml?)模式缩进.到目前为止我尝试了什么:

(defun my-xml-hook ()
  (setq c-tab-always-indent t
        tab-width 4
        indent-tabs-mode t) ; use tabs for indentation
  (setq indent-line-function 'insert-tab)
)
(add-hook 'xml-mode-hook 'my-xml-hook)
(defun local-sgml-mode-hook
  (setq fill-column 70
        indent-tabs-mode t
        next-line-add-newlines nil
        sgml-indent-data t)
  (auto-fill-mode t)
  (setq indent-line-function 'insert-tab)
  )
(add-hook 'psgml-mode-hook '(lambda () (local-psgml-mode-hook)))
Run Code Online (Sandbox Code Playgroud)

没有什么可行,编辑*.xml文件时,仍会在2个空格(emacs23和emacs24)中出现缩进.

请注意,我也有

(setq indent-tabs-mode nil)
Run Code Online (Sandbox Code Playgroud)

在我的.emacs文件中,但是之后应该调用钩子,所以应该重写它.

如何强制emacs缩进*.xml文件中的选项卡?为什么我的钩子不起作用?

xml emacs sgml indentation

4
推荐指数
1
解决办法
4309
查看次数

标签 统计

boost ×1

boost-mpl ×1

c++ ×1

emacs ×1

indentation ×1

sgml ×1

templates ×1

xml ×1