Skip to content

Commit e8c12bb

Browse files
committed
Add C++11 rules for vector/deque::emplace_back
1 parent 5833d1f commit e8c12bb

8 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎rules/deque_cxx11/cxxflags‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-std=c++11

‎rules/deque_cxx11/src.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <deque>
5+
#include <vector>
6+
7+
template <typename T, typename A> using Init = A;
8+
9+
template <typename T1, typename... Args>
10+
void f1(std::deque<T1> &o, Init<T1, Args> &&...args) {
11+
return o.emplace_back(std::forward<Args>(args)...);
12+
}
13+
14+
template <typename T1, typename... Args>
15+
void f2(std::deque<std::vector<T1>> &o,
16+
Init<std::vector<T1>, Args> &&...args) {
17+
return o.emplace_back(std::forward<Args>(args)...);
18+
}

‎rules/deque_cxx11/tgt_refcount.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
use libcc2rs::*;
5+
use std::cell::RefCell;
6+
use std::rc::Rc;
7+
8+
fn f2<T1: ByteRepr>(a0: Ptr<Vec<Value<Vec<T1>>>>, init: Vec<T1>) {
9+
let __init = init;
10+
a0.with_mut(|__v: &mut Vec<Value<Vec<T1>>>| __v.push(Rc::new(RefCell::new(__init))))
11+
}

‎rules/deque_cxx11/tgt_unsafe.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe fn f1<T1>(a0: &mut Vec<T1>, init: T1) {
5+
let __init = init;
6+
a0.push(__init)
7+
}
8+
9+
unsafe fn f2<T1>(a0: &mut Vec<Vec<T1>>, init: Vec<T1>) {
10+
let __init = init;
11+
a0.push(__init)
12+
}

‎rules/vector_cxx11/cxxflags‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-std=c++11

‎rules/vector_cxx11/src.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <vector>
5+
6+
template <typename T, typename A> using Init = A;
7+
8+
template <typename T1, typename... Args>
9+
void f1(std::vector<T1> &o, Init<T1, Args> &&...args) {
10+
return o.emplace_back(std::forward<Args>(args)...);
11+
}
12+
13+
template <typename T1, typename... Args>
14+
void f2(std::vector<std::vector<T1>> &o,
15+
Init<std::vector<T1>, Args> &&...args) {
16+
return o.emplace_back(std::forward<Args>(args)...);
17+
}
18+
19+
template <typename T1, typename T2 = std::allocator<T1>, typename... Args>
20+
void f3(std::vector<T1, T2> &o, Init<T1, Args> &&...args) {
21+
return o.emplace_back(std::forward<Args>(args)...);
22+
}

‎rules/vector_cxx11/tgt_refcount.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
use libcc2rs::*;
5+
use std::cell::RefCell;
6+
use std::rc::Rc;
7+
8+
fn f2<T1: ByteRepr + Clone>(a0: Ptr<Vec<Value<Vec<T1>>>>, init: Vec<T1>) {
9+
let __init = init;
10+
a0.with_mut(|__v: &mut Vec<Value<Vec<T1>>>| __v.push(Rc::new(RefCell::new(__init))))
11+
}

‎rules/vector_cxx11/tgt_unsafe.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe fn f1<T1>(a0: &mut Vec<T1>, init: T1) {
5+
let __init = init;
6+
a0.push(__init)
7+
}
8+
9+
unsafe fn f2<T1>(a0: &mut Vec<Vec<T1>>, init: Vec<T1>) {
10+
let __init = init;
11+
a0.push(__init)
12+
}
13+
14+
unsafe fn f3<T1>(a0: &mut Vec<T1>, init: T1) {
15+
let __init = init;
16+
a0.push(__init)
17+
}

0 commit comments

Comments
 (0)