较新版本的gcc提供了Wimplicit-fallthrough,这对于大多数switch语句都很有用.但是,我有一个switch语句,我希望允许所有case语句的掉头.
有没有办法明确地通过?我宁愿避免Wno-implicit-fallthrough为这个文件编译.
编辑:我正在寻找一种方法来通过显式(如果可能)使下降,而不是通过编译器开关或编译指示关闭警告.
我想获得一个指向映射值(其中包含结构)的指针,以便我可以修改结构中的字段,而无需重新分配它。
type Foo struct {
Bar int64
}
func SomeFunction(arg * Foo) {
...
}
Run Code Online (Sandbox Code Playgroud)
我目前要做的事情:
if val, ok := myMap[idx]; ok {
// val is of type `Foo`
SomeFunction(&val)
myMap[idx] = val
}
Run Code Online (Sandbox Code Playgroud)
我想做的事:
if val, ok := getPointer(myMap, idx); ok {
// val is of type `* Foo`
SomeFunction(val)
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点Go,或者我需要依赖编译器足够聪明来执行复制省略?
我试图使用专门化在头文件和实现之间拆分模板化类,但我希望一种方法仅出现在某些专门化中。
头文件:
template <typename T>
class A
{
public:
void foo();
void bar();
template<typename U = T, typename std::enable_if<std::is_convertible<int,U>::value>::type* = nullptr>
void special();
};
Run Code Online (Sandbox Code Playgroud)
实施:
template<typename T>
void A<T>::foo()
{
...
}
template<typename T>
void A<T>::bar()
{
...
}
template<typename T, typename std::enable_if<std::is_convertible<int,T>::value>::type>
void A<T>::special()
{
...
}
// generate specializations
template
class A<float>;
template
class A<int>;
template
class A<std::string>;
Run Code Online (Sandbox Code Playgroud)
error: declaration is incompatible with function template "void A<T>::special()"然而,当我像这样尝试时,或者当我将 移动std::enable_if为返回类型时,我不断收到消息。定义应该如何与该方法的声明相匹配special()?