我有一个类似的正则表达式
(\d\d\d)(\d\d\d)(\.\d\d){0,1}
Run Code Online (Sandbox Code Playgroud)
当它匹配时,我可以很容易地得到前两组,但我如何检查第三组是否发生了0或1次.
另一个小问题:在(\.\d\d)
我唯一关心的\d\d
部分,任何其他方式告诉正则表达式\.\d\d
需要出现0或1次,但我想只捕获\d\d
部分?
这是基于解析a的问题
HHMMSS
具有可选小数部分的字符串(因此它变为
hhmmss.ss
)...我提出\d\d\d
了这个问题,所以我很清楚\d\d
我在说什么.
就像问题所说,我想知道原因.因为当我试图获得const
非const
迭代器之间的距离时出现错误.
vector<int> v;
auto it=v.begin();
auto cit=v.cbegin();
distance(it,cit);
no matching function for call to ‘distance(__gnu_cxx::__normal_iterator<int*, std::vector<int> >&, __gnu_cxx::__normal_iterator<const int*, std::vector<int> >&)
Run Code Online (Sandbox Code Playgroud)
从我对迭代器的有限理解,我认为没有理由不应该工作.
我知道value_type,key_type ......但它们是在类型上运行,而不是在实例上运行.我试过像这样的东西:
std::set<uint64_t> mySet;
decltype (mySet)::value_type pos;
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
编辑:我使用VS 2010.
EDIT2:这段代码的目的是得到一个类型来赋予它boost :: lexical_cast <>是否有一种解决方法可以实现这一点?我想要这样的东西:
mySet.insert(boost::lexical_cast<decltype(mySet)::value_type>(*it));
// it is a iterator in vector of strings
Run Code Online (Sandbox Code Playgroud)
编辑3:这有效:
mySet.insert(boost::lexical_cast<decltype(mySet)::value_type>(*it));
Run Code Online (Sandbox Code Playgroud) 我想要有类似的东西
unordered_set<vector<pair<int,int>>> us;
Run Code Online (Sandbox Code Playgroud)
但即使没有配对:
#include <vector>
#include <unordered_set>
using namespace std;
int main() {
unordered_set<vector<int>> um;
}
Run Code Online (Sandbox Code Playgroud)
它失败:
In file included from /usr/include/c++/4.8/bits/hashtable.h:35:0,
from /usr/include/c++/4.8/unordered_set:47,
from prog.cpp:2:
/usr/include/c++/4.8/bits/hashtable_policy.h: In instantiation of ‘struct std::__detail::_Hash_code_base<std::vector<int>, std::vector<int>, std::__detail::_Identity, std::hash<std::vector<int> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>’:
/usr/include/c++/4.8/bits/hashtable_policy.h:1402:10: required from ‘struct std::__detail::_Hashtable_base<std::vector<int>, std::vector<int>, std::__detail::_Identity, std::equal_to<std::vector<int> >, std::hash<std::vector<int> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, true, true> >’
/usr/include/c++/4.8/bits/hashtable.h:174:11: required from ‘class std::_Hashtable<std::vector<int>, std::vector<int>, std::allocator<std::vector<int> >, std::__detail::_Identity, std::equal_to<std::vector<int> >, std::hash<std::vector<int> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true> >’
/usr/include/c++/4.8/bits/unordered_set.h:96:18: required from …
Run Code Online (Sandbox Code Playgroud) msvc 编译以下代码(使用 /permissive- 编译器开关),clang 和 gcc不会:
template<auto val>
struct S{
static constexpr auto val = val;
};
int main() {
return S<4>::val;
}
Run Code Online (Sandbox Code Playgroud)
我认为这只是一个 msvc 错误,但我很好奇这里的标准是否含糊不清。
你可能知道typedef更像是C++中的别名而不是新类型,详情可以在这里看到:http:
//dlang.org/cpptod.html#typedefs
我真的不喜欢链接中提出的解决方案,所以我想知道有没有更好的办法 ?
*s.begin()
,但可以使用相同的参数vector
,其中有front
/back
在这里,我说的是设计原因为什么front
/ back
将是糟糕的设计,所以请跳过委员会忘记它的明显原因......
关于lock_guard
存在的原因,我很困惑.是吗:
unique_lock
?unique_lock
?假设我有一个等级向量,其中等级是
struct Grade{
const int grade;
const int ECTS; // weight
};
Run Code Online (Sandbox Code Playgroud)
是否有STL / range-v3算法/算法使我能够做到这一点?
我知道我可以std:: accumulate
用一些花哨的类型作为累加器(记住重量的总和)来做到这一点,但是我正在寻找一个更简单的替代方法(如果存在)。