-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (28 loc) · 1 KB
/
main.cpp
File metadata and controls
38 lines (28 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <msclr/gcroot.h>
#include <msclr/marshal.h>
#include <msclr/marshal_cppstd.h>
#using <System.dll>
/// below are some minimal examples that do or don't work.
/// those that don't compile are commented out.
// this errors out because internal iterators are using constraints on the System::Object
//std::unordered_map<uint64_t, msclr::gcroot<System::Object^>> map;
// vector works?!
std::vector<msclr::gcroot<System::Object^>> vec = {};
void foo()
{
std::vector<msclr::gcroot<System::Object^>> vec = {};
// pushing back does not work though
//vec.push_back(gcnew System::Object());
// iterating somehow works?! even though iterators are involved in this syntax?
for (const auto& obj : vec)
{
std::string s = msclr::interop::marshal_as<std::string>(obj->ToString());
std::cout << s;
}
// any use of iterators does not work either
//const auto itr = std::find(vec.cbegin(), vec.cend(), gcnew System::Object());
}