小编Fre*_*ios的帖子

Angular cli更新后获取错误

我的angular-cli版本是beta.16

我尝试通过以下命令更新

npm uninstall -g angular-cli @angular/cli
npm cache clean
npm install -g @angular/cli@latest
Run Code Online (Sandbox Code Playgroud)

在我尝试运行任何ng命令后成功安装

ng version 
ng help
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

ng help
/usr/local/lib/node_modules/@angular/cli/models/config/config.js:15
    constructor(_configPath, schema, configJson, fallbacks = []) {
                                                           ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/@angular/cli/models/config.js:2:18)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
Run Code Online (Sandbox Code Playgroud)

angular-cli

22
推荐指数
1
解决办法
1万
查看次数

为什么`std :: sto` ...系列不是模板?

我不知道是否有一个原因的std::sto系列(例如std::stoi,std::stol)不是一个函数模板,这样的:

template<typename T>
T sto(std::string const & str, std::size_t *pos = 0, int base = 10);
Run Code Online (Sandbox Code Playgroud)

然后:

template<>
int sto<int>(std::string const & str, std::size_t *pos, int base)
{
    // do the stuff.
}

template<>
long sto<long>(std::string const & str, std::size_t *pos, int base)
{
    // do the stuff.
}

/* etc. */
Run Code Online (Sandbox Code Playgroud)

在我看来,这将是一个更好的设计,因为目前,当我必须转换用户想要的任何数值的字符串时,我必须手动管理每个案例.

有没有理由没有这样的模板功能?是否有一个假定的选择,或者这样做是否就是这样?

c++ c++11

19
推荐指数
3
解决办法
2072
查看次数

是否有队列和堆栈集合?

如果我们需要FIFO或LIFO集合(与基本push,popfront/ back)我们应该在锈使用?像std::queuestd::stack从C++.

rust

19
推荐指数
3
解决办法
5899
查看次数

为什么我可以返回对本地文字但不是变量的引用?

为什么这段代码会编译?

fn get_iter() -> impl Iterator<Item = i32> {
    [1, 2, 3].iter().map(|&i| i)
}

fn main() {
    let _it = get_iter();
}
Run Code Online (Sandbox Code Playgroud)

[1, 2, 3]是一个局部变量并iter()借用它.此代码不应编译,因为返回的值包含对局部变量的引用.

reference rust borrow-checker

18
推荐指数
1
解决办法
1094
查看次数

在调试器中查看C#generic的类型

当我使用调试器将鼠标悬停在Visual Studio中的泛型类型上时,我没有获得当前类型,有没有办法显示它而无需进入即时窗口并键入?typeof(T).Name

c# visual-studio

17
推荐指数
3
解决办法
3773
查看次数

为什么#[derive(Show)]不再起作用了?

使用今天的Rust每晚,以下代码不再编译:

#[derive(Show)]
enum S {
    A,
    B
}

fn main() {
    println!("{}", S::A);
}
Run Code Online (Sandbox Code Playgroud)

相反,它给我以下错误消息:

error: the trait `core::fmt::String` is not implemented for the type `S`
Run Code Online (Sandbox Code Playgroud)

有没有办法得到旧的行为?当然,不需要为每种类型手动实现这一点.

rust rust-obsolete

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

想要类型的constexpr开关案例

我目前正在做这个技巧,以获得基于类型的cstring:

template<class ListT> static char constexpr * GetNameOfList(void)
{
  return
  std::conditional<
    std::is_same<ListT, LicencesList>::value, "licences",
    std::conditional<
      std::is_same<ListT, BundlesList>::value, "bundles",
      std::conditional<
        std::is_same<ListT, ProductsList>::value, "products",
        std::conditional<
          std::is_same<ListT, UsersList>::value, "users",
          nullptr
        >
      >
    >
  >;
}
Run Code Online (Sandbox Code Playgroud)

但是这段代码不是很好看,如果我们想检查更多类型,这可能是不可读的.这是一种做同样的事情的方式,就像有一个开关盒块?

实际上,代码比这更复杂,因为std :: conditional需要一些类型,所以我们需要一些类来做这个技巧:

struct LicenceName { static char constexpr * value = "licences"; };
Run Code Online (Sandbox Code Playgroud)

例如.

c++ templates metaprogramming

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

为什么Rust不能推断出Iterator :: sum的结果类型?

此代码有效:

fn main() {
    let a: i32 = (1i32..10).sum();
    let b = a.pow(2);
}
Run Code Online (Sandbox Code Playgroud)

如果我i32从中删除类型a,那么我收到此错误:

rustc 1.13.0 (2c6933acc 2016-11-07)
error: the type of this value must be known in this context
 --> <anon>:3:13
  |
5 |     let b = a.pow(2);
  |             ^^^^^^^^
Run Code Online (Sandbox Code Playgroud)

运行示例

我原以为Rust会(1i32..10)变成i32迭代器然后sum()知道返回一个i32.我错过了什么?

types type-inference rust

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

如何有效地调试constexpr功能?

在C++ 14中,我们获得了升级版本的constexpr含义,现在可以使用循环,if语句和开关.像C++ 11一样,递归已经成为可能.

我知道constexpr函数/代码应该很简单,但问题仍然存在:如何有效地调试它?

即使在" The C++ Programming Language,4th Edition "中也有一句话,调试可能很难.

c++ debugging constexpr c++11 c++14

15
推荐指数
1
解决办法
1817
查看次数

为什么std :: unique_ptr不允许类型推断?

一切都在标题中.读取/写入我的示例的第二行会更容易,因为模板参数的类型很明显:

#include <memory>

struct Foo{};

int main()
{
  // redundant: good
  auto foo1 = std::unique_ptr<Foo>(new Foo());
  // without explicitness: does not compile
  auto foo2 = std::unique_ptr(new Foo());
}
Run Code Online (Sandbox Code Playgroud)

当然,如果你想使用多态,我们总是写:

auto base = std::unique_ptr<Base>(new Derived());
Run Code Online (Sandbox Code Playgroud)

这种约束的原因是什么?

c++ unique-ptr c++11

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