小编pat*_*pat的帖子

从Xcode 5.1 Project中删除所有调试表达式

我在使用C++和XCode 5.1时偶然添加了一个调试表达式,现在每当我尝试查看我添加此表达式的函数的堆栈时,XCode崩溃了.我不知道如何在不点击该功能的情况下摆脱这个表达式,所以我有点迷失!我找到了一个Expressions.something文件的引用,但那是针对XCode 4的,我没有在XCode 5的任何地方看到它.任何想法?

c++ xcode

6
推荐指数
1
解决办法
758
查看次数

C++ 14 Lambda - 通过引用或值有条件地捕获

是否可以根据编译时间信息有条件地选择lambda的捕获方法?例如...

auto monad = [](auto && captive) {
    return [(?)captive = std::forward<decltype(captive)>(captive)](auto && a) {
        return 1;
    };
};
Run Code Online (Sandbox Code Playgroud)

我希望通过引用捕获,如果decltype(captive)是a std::reference_wrapper,则通过值捕获所有其他内容.

c++ lambda c++14

6
推荐指数
1
解决办法
380
查看次数

二元运算符返回Xvalue而不是PRvalue?

根据这个博客 - 我意识到它已经老了,如果它不再被认为是相关的请告诉我 - 实现二元运算符的最佳方法如下......

// The "usual implementation"
Matrix operator+(Matrix const& x, Matrix const& y)
{ Matrix temp = x; temp += y; return temp; }

// --- Handle rvalues ---

Matrix operator+(Matrix&& temp, const Matrix& y)
{ temp += y; return std::move(temp); }

Matrix operator+(const Matrix& x, Matrix&& temp)
{ temp += x; return std::move(temp); }

Matrix operator+(Matrix&& temp, Matrix&& y)
{ temp += y; return std::move(temp); }
Run Code Online (Sandbox Code Playgroud)

我测试了这个实现,并在以下表达式中...

a + b + c + d …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

5
推荐指数
1
解决办法
180
查看次数

Singletons TypeRepStar Sing数据实例

我是Haskell的新手,所以我可能错过了一些明显的东西,但这里的问题似乎是什么?

该单身库提供Sing了一种例如*import Data.Singletons.TypeRepStar.

Sing数据系列的定义如下..

data family Sing (a :: k)
Run Code Online (Sandbox Code Playgroud)

并且*实例定义为..

data instance Sing (a :: *) where
  STypeRep :: Typeable a => Sing a
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下内容重现最小版本...

{-# LANGUAGE GADTs
           , TypeFamilies
           , PolyKinds
           #-}

module Main where

import Data.Typeable

data family Bloop (a :: k)
data instance Bloop (a :: *) where
  Blop :: Typeable a => Bloop a

main :: IO ()
main = putStrLn "Hello, Haskell!"
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误......

Main.hs:12:3: …
Run Code Online (Sandbox Code Playgroud)

haskell singleton-type

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

C++ constexpr自动成员函数.Clang问题?

 #include <utility>

 struct A {
     constexpr auto one(int a) {
         return std::integral_constant<int, _data[a]>{};
     }
     constexpr int  two(int a) const {
         return _data[a];
     }

     int _data[10];
 };

 int main() {
     constexpr auto ex = A{{1,2,3,4,5,6,7,8,9,10}};

     std::integral_constant<int, ex.two(3)> b{};
 }
Run Code Online (Sandbox Code Playgroud)

上面的代码不会在trunk Clang中编译.错误在one()成员函数中,并说:

cc.cpp:57:44: note: implicit use of 'this' pointer is only allowed 
  within the evaluation of a call to a 'constexpr' member function.
Run Code Online (Sandbox Code Playgroud)

显然,功能标记constexpr,如果你注释掉one()成员,一切编译罚款,所以我们显然能够创建integral_constantex从,但不直接struct?看来,当我需要auto返回类型演绎时,它失败并声称功能不是constexpr

这是预期的吗?我觉得这应该不是问题,如果这是预期的行为,我会感到惊讶.

c++ constexpr auto c++11 c++14

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

榆树中的多态记录类型

榆树有以下几种可能吗?

func : a -> {a | id : Int}
func x = { x | id = 123 }
Run Code Online (Sandbox Code Playgroud)

这无法编译,因为a太多态; 它认为它可以是任何东西,包括非记录类型.如何告诉编译器这a是一种记录类型,但我们不知道任何字段?(老实说,虽然我已经{a | id : Int}足够了).

我试过了...

type alias Record a = {a}
func : Record a -> { a | id : Int }

func : {a} -> {a | id : Int}
func x = { x | id = 123 }
Run Code Online (Sandbox Code Playgroud)

两者都因语法错误而失败.是否有可能对榆树说"这种类型是记录,但我不知道别的什么"?

要解决以下问题:

如果它是一个没有任何特定字段的记录,那么无论如何你都无法做任何类似记录的事情,因此能够表达它似乎没有用.

我试图用我的例子中的未知字段记录做一些类似记录的事情,所以说不能用它们做什么是不正确的.

您无法动态向记录添加字段.

我没有动态地向记录添加字段,我正在创建一个匹配现有的新记录,除了它有一个id有值的字段 …

polymorphism record elm

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

标签 统计

c++ ×4

c++11 ×2

c++14 ×2

auto ×1

constexpr ×1

elm ×1

haskell ×1

lambda ×1

polymorphism ×1

record ×1

singleton-type ×1

xcode ×1