小编Guk*_*ki5的帖子

将返回类型专门化为 void 或 const 左值引用

我正在努力完成以下..

enum class Options : uint8_t {    
    optA,
    optB,
    optC
};

class Test {
public:

    static std::string str;
    static std::vector<std::string> vec;

    template<Options option>
    static auto func()
    {
        if constexpr (option == Options::optA)
        {
            return str; // want this to deduce to 'const std::string', but only does so if 'const auto' (const std::string& also fine though)
        }
        else if constexpr (option == Options::optB)
        {
            return vec; // want this to deduce to 'const std::vector<std::string>&' but only does so if 'const auto&' …
Run Code Online (Sandbox Code Playgroud)

c++ return-type-deduction

5
推荐指数
2
解决办法
103
查看次数

将 C++20 模板化 Lambda 传递给函数然后调用它

我试图将模板化 lambda 传递给函数,然后使用模板参数调用它,以启用该函数针对自定义类型的专门化。

但是当我尝试调用 lambda 时,出现此错误:error: invalid operands to binary expression

对于任何想尝试这个的人来说,这里有一个 godbolt 链接: https: //gcc.godbolt.org/z/qYPcea

#include <cstdint>
#include <string>
#include <cstring>

enum class Alignment : uint8_t {
    
    one,
    two,
    four,
    eight
};

template <Alignment alignment, typename T>
static void align(T& pointer)
{
    intptr_t& value = reinterpret_cast<intptr_t&>(pointer);
    value += (-value) & ((uint64_t)alignment - 1);
}

template<typename Lambda, typename T>
static void specialization(Lambda&& lambda, const T& t) 
{
   lambda<Alignment::eight>(t.data(), t.size());
}

int main()
{
    uint8_t buffer[1024];

    void *writeTo = buffer; …
Run Code Online (Sandbox Code Playgroud)

c++ lambda templates c++20

3
推荐指数
1
解决办法
831
查看次数

UIView AnimateWithDuration从不到达完成块

我有这段代码,我用一个漂亮的小动画切换了根视图控制器,它已经工作了几个月了……但是后来随机停止了工作。

UIView snapshot = [self.window snapshotViewAfterScreenUpdates:YES];
[viewController.view addSubview:snapshot];
self.window.rootViewController = viewController;
NSLog(@"check point 1");
[UIView animateWithDuration:0.3 animations:^{
     NSLog(@"check point 2");
    snapshot.layer.opacity = 0;
     NSLog(@"check point 3");
    snapshot.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5);
     NSLog(@"check point 4");
} completion:^(BOOL finished) {
    NSLog(@"check point 5");
    [snapshot removeFromSuperview];
     NSLog(@"check point 6");
}];
Run Code Online (Sandbox Code Playgroud)

我放入了这些检查点,所有通过检查点4触发的事件..但是5和6从未触发。我觉得很奇怪,因为即使失败,完成块仍然应该触发。

在加载的新的根视图控制器上,请求用户收集其位置的权限。所以也许当弹出窗口出现时,它会破坏这种过渡吗?它曾经不习惯。

uiview ios animatewithduration

2
推荐指数
1
解决办法
1637
查看次数