小编DrY*_*Yap的帖子

在string,u16string和u32string之间转换

我一直在寻找一种在Unicode字符串类型之间进行转换的方法,并且遇到了这种方法.我不仅没有完全理解方法(没有评论),而且文章暗示将来会有更好的方法.

如果这是最好的方法,请指出是什么让它起作用,如果不是,我想听听有关更好方法的建议.

c++ string unicode unicode-string c++11

43
推荐指数
2
解决办法
4万
查看次数

执行std :: initializer_list

我一直在研究如何initializer_list实现,所以我找到了标准的第18.9节,并找到了一个简单的界面.我认为制作我自己命名的版本MyNamespace::InitializerList和用例是有益的:

template<class T>
class ArrayPrinter
{
public:
    ArrayPrinter(MyNamespace::InitializerList<T> list)
    {
        for (auto i : list) cout << i << endl;
    }
};

...

ArrayPrinter ap{ {1,2,3} };
Run Code Online (Sandbox Code Playgroud)

我很惊讶地发现这不起作用,编译器抱怨它找不到合适的构造函数(它想给我3个参数但是第18.9节只描述了一个默认的构造函数).

经过一番摆弄后,我发现我的班级必须完全命名std::initializer_list才能奏效.我还可以别名std::initializer_listMyNamespace,但我不能别名MyNamespace::InitializerListstd::initializer_list.

它似乎不是真正的语言功能,因为它取决于标准库

我的问题的要点是为什么名称如此重要以及它试图传递给构造函数的那3个参数是什么?

c++ initializer-list c++11

19
推荐指数
1
解决办法
3156
查看次数

错误:与`cc` 链接失败:退出代码:1

我有一个单一的.RS文件。当我编译它时rustc test1.rs,我收到一个错误:

    error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'test1' 'test1.o' '-Wl,-force_load,/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-Wl,-dead_strip' '-nodefaultlibs' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-L' '/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin' '-L' '/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin'
ld: can't open output file for writing: test1, errno=21 for architecture x86_64
clang: error: linker command failed with exit code …
Run Code Online (Sandbox Code Playgroud)

macos rust

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

检测用户是否有全屏运行的应用程序

我在C#中做了一个通知程序应用程序,它位于任务栏上,当我从中获取内容时会显示一个气球,类似于Google Talk,当您收到新的电子邮件时,但是如果我在全屏运行应用程序,它会忽略做到这一点就是工作.

如何检测并确保应用程序处于全屏模式?我并不是说最大化(因为应用程序可以在屏幕上最大化但仍然不是全屏模式)但真正的全屏模式.

例如,当您运行游戏时,大多数将以全屏模式运行.

最初GetForegroundWindow()并且GetWindowRect()出现在我的脑海中,但即便如此,如果我不在全屏上,我可以让窗口比我的屏幕大,这对我没有帮助,所以我想知道是否有其他标志或方法来接近这个?

c# desktop-application fullscreen

10
推荐指数
1
解决办法
3628
查看次数

所有std :: tuple构造函数都是必需的吗?

std::tuple 包含以下构造函数:

explicit tuple( const Types&... args );

template< class... UTypes >
explicit tuple( UTypes&&... args );
Run Code Online (Sandbox Code Playgroud)

两者都有相同的描述,因为它们用相应的值初始化每个元素args.唯一的区别是在第二个参数被转发.

根据我对rvalue引用的理解,我不明白为什么第一个版本是必需的,因为相同的参数可以传递到第二个版本.引用将被转发,没有人会更聪明,特别是因为没有提到移动语义.

任何人都可以解释是什么让两个构造函数都必要吗?

c++ rvalue-reference c++11 stdtuple

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

在编译时选择C++字符串文字的默认类型和编码

C++ 11引入的新的字符串文字为UTF-8,16和32与u8,uU前缀但我必须我要使用哪一个硬代码.我正在寻找一种方法来选择我想在编译时使用哪种编码(类似于typedef的工作方式).

用户定义的字符串文字似乎没有帮助,因为它们处理指定编码的字符串.

我已经在前C++ 11代码中看到过使用一个短宏L("string")来选择"string",L"string"但我个人觉得很难看.

是否可以整齐地选择默认类型和编码,还是我必须使用宏选项?

c++ unicode character-encoding string-literals c++11

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

将文字分配给std :: u16string或std :: u32string

据我所知,我可以将一个字面值分配给字符串:

std::string s="good";
std::wstring s=L"good";
Run Code Online (Sandbox Code Playgroud)

我该如何分配给

std::u16string s= 
std::u32string s= 
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

扩展层次结构的具体基类

假设我使用的库提供了以下形状:

class Shape
class Circle extends Shape
class Square extends Shape
Run Code Online (Sandbox Code Playgroud)

但我想介绍红色形状的概念.我无法修改库但我可以创建:

class RedShape extends Shape
Run Code Online (Sandbox Code Playgroud)

然而,这不能轻易扩展到RedCircle因为它不能同时延伸RedShapeCircle.

我不认为装饰器模式在这里工作得很好但是有没有实现这个的技术?

java oop

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

如果两个theads同时锁定互斥锁会怎么样?

我对互斥体的工作原理感兴趣.我了解他们的目的,因为我找到的每个网站都解释了他们的所作所为,但我无法理解在这种情况下会发生什么:

有两个线程同时运行,它们试图同时锁定互斥锁.

这在单核上不会出现问题,因为这种情况永远不会发生,但在多核系统中,我认为这是一个问题.我看不出有任何方法可以防止这样的并发问题,但它们显然存在.

谢谢你的帮助

theory concurrency multithreading mutex thread-safety

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

如何将第一个用户添加到使用Authlogic,Devise等的Rails应用程序?

我有一个Ruby on Rails应用程序,我是从Git repo克隆的.它需要登录才能执行任何操作,例如注册新用户.目前没有注册用户,所以我认为自己完全被锁定了

我知道用户存储在一个被调用的表中,users但底层数据库是MySQL,我不知道如何访问Ruby on Rails应用程序的数据库.

有谁知道如何添加用户?

database authentication ruby-on-rails authlogic devise

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