Skip to content

Commit 5b8dcd1

Browse files
committed
[TPython] Avoid using std::make_any in documentation and tests
The `std::make_any` helper has a different signature on MSVC, so to be truly platform independent we should not use it. We can use `std::any` directly, at the cost of one extra copy.
1 parent 775f235 commit 5b8dcd1

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

bindings/tpython/src/TPython.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
///
4949
/// // Create a TNamed on the python side, and transfer it back and forth.
5050
/// root [1] std::any res1;
51-
/// root [2] TPython::Exec("_anyresult = ROOT.std.make_any['TNamed']('hello', '')", &res1);
51+
/// root [2] TPython::Exec("_anyresult = ROOT.std.any(ROOT.TNamed('hello', ''))", &res1);
5252
/// root [3] TPython::Bind(&std::any_cast<TNamed&>(res1), "n");
5353
/// root [4] std::any res2;
54-
/// root [5] TPython::Exec("_anyresult = ROOT.std.make_any['TNamed*', 'TNamed*'](n)", &res2);
55-
/// root [6] (&std::any_cast<TNamed&>(res1) == std::any_cast<TNamed*>(res2))
54+
/// root [5] TPython::Exec("_anyresult = ROOT.std.any(n)", &res2);
55+
/// root [6] strcmp(std::any_cast<TNamed&>(res1).GetName(), std::any_cast<TNamed&>(res2).GetName()) == 0
5656
/// (bool) true
5757
///
5858
/// // Variables can cross-over by using an `std::any` with a specific name.
59-
/// root [6] TPython::Exec("_anyresult = ROOT.std.make_any['Int_t'](1 + 1)", &res1);
59+
/// root [6] TPython::Exec("_anyresult = ROOT.std.any(1 + 1)", &res1);
6060
/// root [7] std::any_cast<int>(res1)
6161
/// (int) 2
6262
/// ~~~

bindings/tpython/test/testTPython.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ TEST(TPython, ExecMultithreading)
3737

3838
// In the end, let's check if the size is correct.
3939
std::any len;
40-
TPython::Exec("_anyresult = ROOT.std.make_any['int'](len(arr))", &len);
40+
TPython::Exec("_anyresult = ROOT.std.any(len(arr))", &len);
4141
EXPECT_EQ(std::any_cast<int>(len), nThreads);
4242
}

bindings/tpython/test/test_tpython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_exec(self):
2121
{
2222
std::any out;
2323
std::stringstream cmd;
24-
cmd << "_anyresult = ROOT.std.make_any['int'](" << nIn << ")";
24+
cmd << "_anyresult = ROOT.std.any(" << nIn << ")";
2525
TPython::Exec(cmd.str().c_str(), &out);
2626
return std::any_cast<int>(out);
2727
}

0 commit comments

Comments
 (0)