我正在尝试创建一个接受底层容器的函数,并根据对元素进行一些处理的自定义迭代器返回一个boost :: iterator_range.
例如
// The range class, templated on the underlying iterator type
template<class Iter> using CustomRange = boost::iterator_range<CustomIterator<Iter>>;
using std::begin;
template <class Container>
auto make_custom_range(Container& c) -> CustomRange<decltype(begin(c))> {
using std::end;
return make_custom_range_from_iterators(begin(c),end(c));
}
Run Code Online (Sandbox Code Playgroud)
代码有效(给定CustomIterator和make_custom_range_from_iterators的合适定义).
我担心的是 using std::begin声明,我认为这将导致std :: begin被导入到声明我的函数的整个命名空间.我不喜欢在decltype中明确使用std :: begin,这样ADL就可以工作了(就像这个问题:依赖于ADL for std :: begin()和std :: end()?).
我想在C++ 14中,我可以在这里使用自动返回类型.有C++ 11解决方案吗?有没有办法让返回类型看到using声明而不将它暴露给整个命名空间?
道歉似乎是一个基本问题.我试图弄清楚如何将Data.Text转换为Char的向量.我能想到的最好的是:
textToVec :: T.Text -> V.Vector Char
textToVec t = T.foldr append V.empty t where
append c vec = V.snoc vec c
Run Code Online (Sandbox Code Playgroud)
这看起来有点复杂(并且计算效率低下?)是否有更好的方法?
更一般地说,作为一名Haskell新手,我很欣赏任何有关如何为自己搞清楚这类事情的建议.我无法从谷歌或搜索文档中取得很大进展.
我正在使用colorama模块,并且希望能够在与颜色对应的变量上调用Fore,例如“ GREEN”。我希望能够做到:
from colorama import Fore
color = 'GREEN'
print(Fore. + color)
Run Code Online (Sandbox Code Playgroud)
我希望它仅运行print(Fore.GREEN),但我不能,因为它存在语法错误。有什么办法吗?