本文整理汇总了C++中std::vector::emplace方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::emplace方法的具体用法?C++ vector::emplace怎么用?C++ vector::emplace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::vector
的用法示例。
在下文中一共展示了vector::emplace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalculatePath
bool World::CalculatePath(Vector &start, Vector &finish, std::vector<Vector> &path)
{
Tile *start_tile = GetTile(start);
if(!start_tile)
{
return false;
}
Tile *finish_tile = GetTile(finish);
if(!finish_tile)
{
return false;
}
bool result = TileMap::CalculatePath(start_tile, finish_tile);
if(result)
{
for(Tile *tile = GetTile(finish); tile; tile = tile->GetParent())
{
path.emplace(path.begin(),
(TileW * tile->GetX()) + (TileW / 2),
(TileH * tile->GetY()) + (TileH / 2)
);
}
}
return result;
}
示例2: PrepareCallAssembly
/// <summary>
/// Generate assembly code for remote call.
/// </summary>
/// <param name="a">Underlying assembler object</param>
/// <param name="pfn">Remote function pointer</param>
/// <param name="args">Function arguments</param>
/// <param name="cc">Calling convention</param>
/// <param name="retType">Return type</param>
/// <returns>true on success</returns>
bool RemoteExec::PrepareCallAssembly( AsmHelperBase& a,
const void* pfn,
std::vector<AsmVariant>& args,
eCalligConvention cc,
eReturnType retType )
{
size_t data_offset = ARGS_OFFSET;
// Invalid calling convention
if (cc < cc_cdecl || cc > cc_fastcall)
{
LastNtStatus( STATUS_INVALID_PARAMETER_3 );
return false;
}
// Copy structures and strings
for (auto& arg : args)
{
if (arg.type == AsmVariant::dataStruct || arg.type == AsmVariant::dataPtr)
{
_userData.Write( data_offset, arg.size, reinterpret_cast<const void*>(arg.imm_val) );
arg.new_imm_val = _userData.ptr<size_t>() + data_offset;
// Add some padding after data
data_offset += arg.size + 0x10;
}
}
// Insert hidden variable if return type is struct.
// This variable contains address of buffer in which return value is copied
if (retType == rt_struct)
{
args.emplace( args.begin(), AsmVariant( _userData.ptr<size_t>() + ARGS_OFFSET ) );
args.front().new_imm_val = args.front().imm_val;
args.front().type = AsmVariant::structRet;
}
a.GenPrologue();
a.GenCall( pfn, args, cc );
// Retrieve result from XMM0 or ST0
if (retType == rt_float || retType == rt_double)
{
a->mov( asmjit::host::zax, _userData.ptr<size_t>() + RET_OFFSET );
#ifdef USE64
if (retType == rt_double)
a->movsd( asmjit::host::Mem( asmjit::host::zax, 0 ), asmjit::host::xmm0 );
else
a->movss( asmjit::host::Mem( asmjit::host::zax, 0 ), asmjit::host::xmm0 );
#else
a->fstp( asmjit::host::Mem( asmjit::host::zax, 0, retType * sizeof(float) ) );
#endif
}
AddReturnWithEvent( a, mt_default, retType );
a.GenEpilogue();
return true;
}
示例3: GetInstalled
void CAddonDatabase::GetInstalled(std::vector<CAddonBuilder>& addons)
{
try
{
if (NULL == m_pDB.get()) return;
if (NULL == m_pDS.get()) return;
m_pDS->query(PrepareSQL("SELECT * FROM installed"));
while (!m_pDS->eof())
{
auto it = addons.emplace(addons.end());
it->SetId(m_pDS->fv("addonID").get_asString());
it->SetInstallDate(CDateTime::FromDBDateTime(m_pDS->fv("installDate").get_asString()));
it->SetLastUpdated(CDateTime::FromDBDateTime(m_pDS->fv("lastUpdated").get_asString()));
it->SetLastUsed(CDateTime::FromDBDateTime(m_pDS->fv("lastUsed").get_asString()));
it->SetOrigin(m_pDS->fv("origin").get_asString());
m_pDS->next();
}
m_pDS->close();
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
}
}
示例4: emplace
void emplace(Args&&... args) {
detail::is_component<T>();
std::unique_ptr<Component> c{ new T(std::forward<Args>(args)...) };
auto&& id = std::type_index(typeid(T));
auto&& it = find(id);
components.emplace(it, id, std::move(c));
}
示例5: minesweeper
std::vector<std::vector<int>> minesweeper(std::vector<std::vector<bool>> matrix) {
int x = matrix[0].size();
int y = matrix.size();
std::vector<bool> m_allFalse(x + 2);
std::vector<std::vector<int>> r;
for(int i = 0;i < matrix.size();i++){
matrix[i].emplace(matrix[i].begin(), 0);
matrix[i].push_back(0);
}
matrix.emplace(matrix.begin(), m_allFalse);
matrix.push_back(m_allFalse);
for(int i = 1; i < matrix.size() - 1;i++){
std::vector<int> q(x);
for(int j = 1; j < matrix[0].size();j++){
for(int a = i - 1;a < i + 2;a++)
for(int b = j - 1;b < j + 2;b++){
if(matrix[a][b]) q[j - 1]++;
}
if(matrix[i][j]) q[j - 1]--;
}
r.push_back(q);
}
return r;
}
示例6: insertInitListProxy
void insertInitListProxy(std::vector<VecT> & Cnt, Iterator pos, std::initializer_list<LType> il)
{
// pre-allocate space
Cnt.reserve(Cnt.size() + il.size());
// construct the items in-place
for (auto it = il.begin(); it < il.end(); ++it)
pos = Cnt.emplace(pos, *it) + 1;
}
示例7: taPushFront
inline void taPushFront(const T& mX)
{
// Instant
data.emplace(std::begin(data), mX);
auto& ts(create<TextSquare>(ssvs::zeroVec2f));
auto xStr(ssvu::toStr(mX));
// Timed
this->createTA() += [this, &ts](auto&, FT)
{
tss.emplace(std::begin(tss), &ts);
};
this->createTA() += [this](auto&, FT)
{
this->refreshPositions();
};
ts.taShow();
ts = xStr;
}
示例8: itemCreated
void itemCreated(const std::string& file)
{
auto it = std::lower_bound(m_dirEntries.begin(), m_dirEntries.end(), file, Cmp());
it = m_dirEntries.emplace(it, file);
std::string filePatch = m_dir.path();
if (!endsWith(filePatch, '/'))
filePatch.push_back('/');
filePatch.append(file);
if (stat64(filePatch.c_str(), &it->info) == -1) {
m_dirEntries.erase(it);
return;
}
q->itemInserted(it - m_dirEntries.begin());
}
示例9: updateClientContainer
CXIdxClientContainer updateClientContainer(const CXIdxEntityInfo* info, const CXIdxLoc l)
{
std::string container;
if (info->name)
container = info->name;
else
container = "<anonymous-tag>";
//
location loc = {l};
auto result = std::string{loc.file().toLocalFile().toUtf8().constData()} + ":"
+ std::to_string(loc.line()) + ":"
+ std::to_string(loc.column()) + ": "
+ container
;
auto& ptr = *m_containers.emplace(end(m_containers), new std::string(std::move(result)));
return CXIdxClientContainer(ptr.get());
}
示例10: run
inline static void run(std::vector<T> &c, std::size_t size) {
for(std::size_t i=0; i<size; ++i) {
c.emplace(begin(c));
}
}
示例11: bad_emplace_vector1
void bad_emplace_vector1(std::vector<int> &V, int n) {
auto i1 = V.cbegin(), i0 = i1++;
V.emplace(i1, n);
*i1; // expected-warning{{Invalidated iterator accessed}}
}
示例12: addAt
void addAt(T value, size_t loc = 0) {
m->emplace(m.begin() + loc, value);
}
示例13: good_emplace_vector1
void good_emplace_vector1(std::vector<int> &V, int n) {
auto i1 = V.cbegin(), i0 = i1++;
V.emplace(i1, n);
*i0; // no-warning
}
示例14: greedy_path
void greedy_path()
{
//cout << "Inside funciton ";
std::unordered_set<int> s;
while (s.size() < 3)
{
//cout << "In while";
srand(time(NULL));
s.insert(rand()%count);///or count-1?????
}
//int path[num_cities+2];
int k=0;
//std::vector<int>::iterator k;
//k = path.begin();
std::unordered_set<int>::iterator it;
for(it=s.begin();it!=s.end();++it)
{
//path[k]=*it;
//cout << *it << " ";
path.push_back(*it);
k++;
//path.emplace(k,*it);
//k++;
}
it=s.begin(); double d1,d2,d3; int m;double cost,minCost;
path.push_back(*it);
k++;
//auto iit=path.begin();
//while(iit != path.end())
//{
// cout << *iit << " ";
// ++iit;
//}
//cout << endl;
// cout << "HI" << endl;
//path.emplace(k++,*it); /*from here!!
for(int i=1;i<count;i++)
{
//cout << "Inside loop" << " ";
bool found = false;
for(auto k1=path.begin();k1!=path.end();k1++)
{
if(*k1 == i)
{
found = true;
break;
}
}
if(found == false)
{
// cout << "Inside false if ";
m=0;
d1=distances[path[m]][i];
d2=distances[path[m+1]][i];
d3=distances[path[m]][path[m+1]];
minCost = ( d1 + d2 ) - d3;
for(int l=1;l<k-1;l++)
{
d1=distances[path[l]][i];
d2=distances[path[l+1]][i];
d3=distances[path[l]][path[l+1]];
cost=(d1+d2)-d3;
if(cost<minCost)
{
minCost=cost;
m=l;
}
}
std::vector<int>::iterator myit = path.begin();
myit+=(m+1);
//if(m == 0)
//{
// cout << "\nWHOA!\n";
//}
path.emplace(myit,i);
k++;
}
}
//for(int x=0;x<k;x++)
// cout << path[x] << " ";
//cout << endl;
fwd.push_back(0);
bkd.push_back(0);
std::vector<int>::iterator i1,i2;
for(int i=1;i<count;i++)
//.........这里部分代码省略.........
示例15: good_emplace
void good_emplace(std::vector<int> &v, int n) {
v.emplace(v.cbegin(), n); // no-warning
}