我试图理解为什么有人会编写一个带有const右值引用的函数.
在下面的代码示例中,const rvalue引用函数的用途是什么(返回"3").为什么重载决策首选const Rvalue高于const LValue引用函数(返回"2").
#include <string>
#include <vector>
#include <iostream>
std::vector<std::string> createVector() { return std::vector<std::string>(); }
//takes movable rvalue
void func(std::vector<std::string> &&p) { std::cout << "1"; }
//takes const lvalue
void func(const std::vector<std::string> &p) { std::cout << "2"; }
//takes const rvalue???
//what is the point of const rvalue? if const I assume it is not movable?
void func(const std::vector<std::string> &&p) { std::cout << "3"; }
int main()
{
func(createVector());
return 0;
}
Run Code Online (Sandbox Code Playgroud) MSVC10是否支持C++ 0x draft标准的基于范围的循环?
http://en.wikipedia.org/wiki/C%2B%2B0x#Range-based_for-loop
例:
for (int& p : array) { ... }
Run Code Online (Sandbox Code Playgroud) 我已通过设置Project Settings |来配置Visual Studio 2010以调试xUnit.net测试 调试| 启动外部程序以运行xUnit.net控制台运行程序.
这工作正常,但只有在通过命令行参数提供测试项目dll的完整路径时,例如:"c:\ development\TestProject.dll"
我尝试通过命令行参数部分使用$(BinDir)$(TargetName)$(TargetExt)作为参数,但它不起作用.有关如何避免显式/完整路径的任何建议?
如何修改mercurial.ini文件以包含环境变量,例如%userprofile%.
具体情况:
我正在学习使用Mercurial.我修改了Mercurial.ini的[ui]部分(在我的主路径中),包括:
ignore = c:\users\user\.hgignore
Run Code Online (Sandbox Code Playgroud)
当用户是我的用户名文字..hgignore文件包含用于在提交期间忽略文件的文件名过滤器.如何将其从文字用户更改为环境变量$ user?
我正在开发一个具有基于消息/异步代理类架构的应用程序。将有几十种不同的消息类型,每一种都由 C++ 类型表示。
class message_a
{
long long identifier;
double some_value;
class something_else;
...//many more data members
}
Run Code Online (Sandbox Code Playgroud)
是否可以编写允许在编译时计算类中数据成员数量的宏/元程序?
//例如:
class message_b
{
long long identifier;
char foobar;
}
bitset<message_b::count_members> thebits;
Run Code Online (Sandbox Code Playgroud)
我不熟悉 C++ 元编程,但是 boost::mpl::vector 可以让我完成这种类型的计算吗?
Visual Studio 2010 MSVC10是否支持显式转换运算符,还是仍然需要实现的安全bool习惯用法?
此代码无法编译:
explicit operator bool() const
{
return Traits::invalid() != value;
}
Run Code Online (Sandbox Code Playgroud)
编译器错误: 错误C2071:foo :: operator bool':非法存储类
我一直在调查Windows事件跟踪(ETW),以便在现有的后端/服务器应用程序中使用.MSDN和其他消息来源已经出售了框架的功能以及它与xperf等的集成,坦白地说我印象深刻.
但是我对win32 apis以及使用清单编码编译/注册等的开销有点担心.
伙计们,你们:
我相信我对boost :: mpl :: set的理解必然存在根本缺陷.我认为它只允许独特的类型.
但是以下代码编译:
#include <boost/mpl/set.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/accumulate.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/sizeof.hpp>
#include <boost/mpl/assert.hpp>
using namespace boost::mpl;
typedef set<long,float,long> my_set; //long repeated in set?
typedef vector<long,float,long> my_vec; //seems reasonable
typedef accumulate<
my_set
, int_<0>
, plus<_1, sizeof_<_2>>
>::type set_size;
typedef accumulate<
my_vec
, int_<0>
, plus<_1, sizeof_<_2>>
>::type vec_size;
BOOST_MPL_ASSERT_RELATION( vec_size::value, ==, sizeof(long)+sizeof(float)+sizeof(long) );
//why does the following line compile?
//shouldn't the size be sizeof(long)+sizeof(float) instead?
BOOST_MPL_ASSERT_RELATION( set_size::value, ==, sizeof(long)+sizeof(float)+sizeof(long) …Run Code Online (Sandbox Code Playgroud) 在C ++中,有没有一种机制可以表达未终止的宏?这是一个人为的示例:
#define MACRO(x, y) x + y
#define MACROC1(x) MACRO(x,
#define MACROC2(y) y)
//...expecting 3
int foo = MACROC1(1) MACROC2(2);
Run Code Online (Sandbox Code Playgroud)
我从MSVC收到错误终止宏调用错误。
当我运行cl -E file.cpp时,我看到下面的代码已经生成:
int c = 1 + 1 + 2);
Run Code Online (Sandbox Code Playgroud)
在Visual Studio中,编译失败并显示以下错误:错误C2059:语法错误:')'IntelliSense:不正确终止的宏调用
我们正尝试使用ICollectionView在ComboBox中实现简单的项目分组.CollectionView中使用的分组和排序正常工作.但是ComboBox创建的弹出项目列表无法按预期运行,因为滚动条滚动组而不是项目.
例如:如果有2组25个项目,那么滚动条将有两个位置/点滚动而不是所需的50.
有人可以解释为什么滚动条滚动组而不是组内的项目,以及我们如何改变这种行为?
Viewmodel设置ICollectionView:
public ViewModel()
{
CurrenciesView.Filter = CurrencyFilter;
CurrenciesView.SortDescriptions.Add(new SortDescription("MajorCurrency", ListSortDirection.Descending));
CurrenciesView.SortDescriptions.Add(new SortDescription("Code", ListSortDirection.Ascending));
CurrenciesView.GroupDescriptions.Add(new PropertyGroupDescription("MajorCurrency", new CurrencyGroupConverter()));
public ICollectionView CurrenciesView { get { return CollectionViewSource.GetDefaultView(currencies); } }
private ObservableCollection<Currency> currencies = new ObservableCollection<Currency>();
public ObservableCollection<Currency> Currencies
{
get { return this.currencies; }
set
{
if (this.currencies != value)
{
this.currencies = value;
this.PropertyChanged(this, new PropertyChangedEventArgs("Currencies"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
托管ComboBox的XAML UserControl
<UserControl x:Class="FilterView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:ViewModels">
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate x:Key="CurrencyItem">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Code}" FontWeight="ExtraBold"/> …Run Code Online (Sandbox Code Playgroud)