我正在使用列表与向量进行一些实验,我注意到std :: vector的Microsoft实现正在为.insert执行以下操作:
iterator insert(const_iterator _Where, _Ty&& _Val)
{ // insert by moving _Val at _Where
return (emplace(_Where, _STD move(_Val)));
}
iterator emplace(const_iterator _Where \
COMMA LIST(_TYPE_REFREF_ARG)) \
{ /* insert by moving _Val at _Where */ \
size_type _Off = _VIPTR(_Where) - this->_Myfirst; \
_VECTOR_EMPLACE_CHECK \
emplace_back(LIST(_FORWARD_ARG)); \
_STD rotate(begin() + _Off, end() - 1, end()); \
return (begin() + _Off); \
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚vs2012中的旋转功能,但在2015年这样做:
template<class _RanIt> inline
_RanIt _Rotate(_RanIt _First, _RanIt _Mid, _RanIt _Last,
random_access_iterator_tag)
{ // rotate [_First, …Run Code Online (Sandbox Code Playgroud) 我正在玩std :: function和std :: bind,我注意到一些不直观的东西,我想更好地理解它.
例如:
void fun()
{
}
void hun(std::string)
{
}
int main()
{
function<void(int)> g = &fun; //This fails as it should in my understanding.
function<void(int)> f = std::bind(fun); //This works for reasons unknown to me
function<void(int, std::string)> h = std::bind(hun); //this doesn't work
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何function<void(int)>将一个函数绑定到void().然后我可以调用f(1)并获得乐趣().我想了解这是如何完成的.进入微软Visual Studio 2012的实现,让我迷失在无法理解的宏观之中.所以这就是我在这里问这个问题的原因.
我正在尝试新增的右值参考(在vs2012 express中).
我不明白.给出下面的代码(大部分来自c ++标准,其中解释了std :: forward).
struct A
{
A(int& i, const float& j):
m_i(i),
m_j(j){}
int& m_i;
const float& m_j;
};
template<class T, class A1, class A2>
T* factory(A1&& a1, A2&& a2)
{
return new T(a1, a2);
}
void test()
{
A* a1 = factory<A>(1, 1.2f);
//How does this work ?
a1->m_i = 2;
}
Run Code Online (Sandbox Code Playgroud)
我不明白m_i绑定到哪里.
我将基本上有一个左值引用到右值引用(&&&),ref refpsing规则变为(&)只是一个简单的左值引用.但是参考什么?
我最近一直有一个奇怪的问题.根据我在Windows(立体声/四/ 5.1)中设置音频配置的方式,对avcodec_open2()的ffmpeg调用失败,错误为-22或者正常工作.我无法找到很多关于这个错误,我想我应该在这里问一下.主要流程如下:
c = st->codec;
avformat_alloc_output_context2(&oc, NULL, NULL, "video.mpeg");
oc->fmt->audio_codec = AV_CODEC_ID_MP2;
AVDictionary* dict = NULL;
ret = av_dict_set(&dict, "ac", "2", 0);
c->request_channels = 2;
ret = avcodec_open2(c, codec, &dict); //HERE IT FAILS WITH -22 if speaker configuration is not stereo
Run Code Online (Sandbox Code Playgroud)
编解码器上下文'c'在流中设置如下:
st = avformat_new_stream(oc, *codec);
c = st->codec;
c->channels = 2;
c->channel_layout = AV_CH_LAYOUT_STEREO;
c->sample_fmt = AV_SAMPLE_FMT_S16;
c->codec_id = codec_id;
Run Code Online (Sandbox Code Playgroud)
其中大部分都是从文档中的一个复用示例中复制而来.如果在Windows中我将输出设置为立体声,一切都按预期工作.
如果我将扬声器配置设置为5.1(6个通道),avcodec_open2将失败并显示错误-22.
所以我很难理解我做错了什么.通常它不应该是我的扬声器配置和avcodec_open2的结果之间的任何关系.
我需要设置一些其他参数吗?
c++ ×3
c++11 ×3
c ×1
ffmpeg ×1
rvalue ×1
std-function ×1
stdbind ×1
stl ×1
vector ×1
visual-c++ ×1