Skip to content

Commit d08d223

Browse files
committed
update latest reference guide
1 parent f32c02d commit d08d223

File tree

10,678 files changed

+2282454
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

10,678 files changed

+2282454
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Converting between xtd and std collections
2+
3+
## In this article
4+
5+
* [Collections](#collections)
6+
* [Sequence collections](#sequence-collections)
7+
* [Associative collections](#associative-collections)
8+
* [Unordered associative collections](#unordered-associative-collections)
9+
* [Collections adaptors](#container-adaptors)
10+
* [Collections with events](#collections-with-events)
11+
* [Specialized collections](#specialized-collections)
12+
* [Thread-safe collections](#thread-safe-collections)
13+
* [Choose a collection](#choose-a-collection)
14+
* [Algorithmic complexity of collections](#algorithmic-complexity-of-collections)
15+
16+
17+
In many cases, you may want to exchange data between xtd::collections::generic containers and their standard C++ (std) equivalents.
18+
While both libraries provide similar abstractions, their types are distinct and sometimes require explicit conversion.
19+
20+
This guide presents the different ways to convert collections in both directions.
21+
22+
## Example
23+
24+
```cpp
25+
#include <xtd/xtd>
26+
27+
auto main() -> int {
28+
auto l = list<string> {"one", "two", "three", "four", "five"};
29+
println("l = {}", l);
30+
31+
auto v = std::vector<std::string> {"one", "two", "three", "four", "five"};
32+
println("v = {}", v);
33+
34+
println();
35+
36+
// xtd::collections::generic::list<xtd::string> -> std::vector<xtd::string>
37+
auto v1 = std::vector<string>(l); // direct construction
38+
println("v1 = {}", v1);
39+
40+
// xtd::collections::generic::list<xtd::string> -> std::vector<std::string>
41+
auto v2 = std::vector<std::string>(l.cast<std::string>()); // explicit cast
42+
println("v2 = {}", v2);
43+
44+
// xtd::collections::generic::list<xtd::string> -> std::vector<std::string>
45+
auto v3 = std::vector<std::string>(l.size());
46+
std::transform(l.begin(), l.end(), v3.begin(), [](const auto& s) {return s;}); // manual transform
47+
println("v3 = {}", v3);
48+
49+
// Move xtd::collections::generic::list<xtd::string> -> std::vector<xtd::string>
50+
auto v4 = std::vector<string>(std::move(l.items())); // using underlying collection
51+
println("v4 = {}", v4);
52+
53+
println();
54+
55+
// std::vector<std::string> -> xtd::collections::generic::list<std::string>
56+
auto l1 = list<std::string>(v); // direct construction
57+
println("l1 = {}", l1);
58+
59+
// std::vector<std::string> -> xtd::collections::generic::list<xtd::string>
60+
auto l2 = list<string>(from(v).cast<string>()); // explicit cast using xtd::linq extension
61+
println("l2 = {}", l2);
62+
63+
// std::vector<std::string> -> xtd::collections::generic::list<xtd::string>
64+
auto l3 = list<string>(v.size());
65+
std::transform(v.begin(), v.end(), l3.begin(), [](const auto& s) {return s;}); // manual transform
66+
println("l3 = {}", l3);
67+
68+
// Move std::vector<std::string> -> xtd::collections::generic::list<std::string>
69+
auto l4 = list<std::string>(std::move(v));
70+
println("l4 = {}", l4);
71+
72+
println();
73+
74+
println("l = {}", l);
75+
println("v = {}", v);
76+
}
77+
```
78+
79+
**Output:**
80+
81+
```
82+
l = [one, two, three, four, five]
83+
v = [one, two, three, four, five]
84+
85+
v1 = [one, two, three, four, five]
86+
v2 = [one, two, three, four, five]
87+
v3 = [one, two, three, four, five]
88+
v4 = [one, two, three, four, five]
89+
90+
l1 = [one, two, three, four, five]
91+
l2 = [one, two, three, four, five]
92+
l3 = [one, two, three, four, five]
93+
l4 = [one, two, three, four, five]
94+
95+
l = []
96+
v = []
97+
```
98+
99+
## Conversion strategies
100+
101+
### 1. Direct construction
102+
103+
If the element type is compatible (xtd::string to xtd::string, or std::string to std::string), you can directly construct a std::vector from a xtd::list (or the other way around).
104+
105+
```cpp
106+
auto v = std::vector<string>(l);
107+
auto l = list<std::string>(v);
108+
```
109+
110+
# See also
111+
112+
* [Guides](/docs/documentation/guides)
113+
* [Documentation](/docs/documentation)
114+
115+
[//]: # (https://learn.microsoft.com/en-us/dotnet/standard/collections/)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5+
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6+
<title>xtd: xtd.core/include/xtd/internal/__array_definition.hpp File Reference</title>
7+
<link href="favicon.png" rel="shortcut icon" type="image/png"/>
8+
<link href="tabs.css" rel="stylesheet" type="text/css"/>
9+
<script type="text/javascript" src="jquery.js"></script>
10+
<script type="text/javascript" src="dynsections.js"></script>
11+
<link href="search/search.css" rel="stylesheet" type="text/css"/>
12+
<script type="text/javascript" src="search/searchdata.js"></script>
13+
<script type="text/javascript" src="search/search.js"></script>
14+
<link href="doxygen.css" rel="stylesheet" type="text/css" />
15+
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
16+
<link href="custom_images.css" rel="stylesheet" type="text/css"/>
17+
<script type="text/javascript" src="doxygen-awesome-darkmode-toggle.js"></script>
18+
<script type="text/javascript"> DoxygenAwesomeDarkModeToggle.init() </script>
19+
</head>
20+
<body>
21+
<div id="page_container">
22+
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
23+
<div id="titlearea">
24+
<table cellspacing="0" cellpadding="0" style="width: 100%;">
25+
<tbody>
26+
<tr>
27+
<td id="projectlogo">
28+
<a href="https://gammasoft71.github.io/xtd/" target="_new">
29+
<img alt="Logo" src="xtd_doxygen.png"/>
30+
</a>
31+
</td>
32+
<td id="projectalign" style="padding-left: 0.5em; text-align: right;">
33+
<div id="projectname">xtd
34+
<span id="projectnumber">0.2.0</span>
35+
</div>
36+
</td>
37+
</tr>
38+
</tbody>
39+
</table>
40+
</div>
41+
<!-- end header part -->
42+
<!-- Generated by Doxygen 1.9.7 -->
43+
<script type="text/javascript">
44+
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
45+
var searchBox = new SearchBox("searchBox", "search/",'.html');
46+
/* @license-end */
47+
</script>
48+
<script type="text/javascript" src="menudata.js"></script>
49+
<script type="text/javascript" src="menu.js"></script>
50+
<script type="text/javascript">
51+
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
52+
$(function() {
53+
initMenu('',true,false,'search.php','Search');
54+
$(document).ready(function() { init_search(); });
55+
});
56+
/* @license-end */
57+
</script>
58+
<div id="main-nav"></div>
59+
<!-- window showing the filter options -->
60+
<div id="MSearchSelectWindow"
61+
onmouseover="return searchBox.OnSearchSelectShow()"
62+
onmouseout="return searchBox.OnSearchSelectHide()"
63+
onkeydown="return searchBox.OnSearchSelectKey(event)">
64+
</div>
65+
66+
<!-- iframe showing the search results (closed by default) -->
67+
<div id="MSearchResultsWindow">
68+
<div id="MSearchResults">
69+
<div class="SRPage">
70+
<div id="SRIndex">
71+
<div id="SRResults"></div>
72+
<div class="SRStatus" id="Loading">Loading...</div>
73+
<div class="SRStatus" id="Searching">Searching...</div>
74+
<div class="SRStatus" id="NoMatches">No Matches</div>
75+
</div>
76+
</div>
77+
</div>
78+
</div>
79+
80+
<div id="nav-path" class="navpath">
81+
<ul>
82+
<li class="navelem"><a class="el" href="dir_dc97fa897e7997e4ee808021e868856c.html">xtd.core</a></li><li class="navelem"><a class="el" href="dir_cd4d13b1160eb35a323b5c83cf3e9e5e.html">include</a></li><li class="navelem"><a class="el" href="dir_8bddd848f68e3e28b5aa5e234df2e4b1.html">xtd</a></li><li class="navelem"><a class="el" href="dir_618e153bd4f02720ed2e807a9fe886a0.html">internal</a></li> </ul>
83+
</div>
84+
</div><!-- top -->
85+
<div class="header">
86+
<div class="summary">
87+
<a href="#namespaces">Namespaces</a> </div>
88+
<div class="headertitle"><div class="title">__array_definition.hpp File Reference</div></div>
89+
</div><!--header-->
90+
<div class="contents">
91+
<div class="textblock"><code>#include &quot;<a class="el" href="allocator_8hpp_source.html">../collections/generic/helpers/allocator.hpp</a>&quot;</code><br />
92+
<code>#include &quot;<a class="el" href="xtd_8core_2include_2xtd_2size_8hpp_source.html">../size.hpp</a>&quot;</code><br />
93+
<code>#include &lt;vector&gt;</code><br />
94+
</div><a name="details" id="details"></a><h2 class="groupheader">Definition</h2>
95+
<div class="textblock"><p>Contains <a class="el" href="classxtd_1_1array.html" title="Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...">xtd::array</a> definitions. </p>
96+
<dl class="section copyright"><dt>Copyright</dt><dd>Copyright (c) 2025 Gammasoft. All rights reserved. </dd></dl>
97+
</div>
98+
<p><a href="____array__definition_8hpp_source.html">Go to the source code of this file.</a></p>
99+
<table class="memberdecls">
100+
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
101+
Namespaces</h2></td></tr>
102+
<tr class="memitem:namespacextd"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespacextd.html">xtd</a></td></tr>
103+
<tr class="memdesc:namespacextd"><td class="mdescLeft">&#160;</td><td class="mdescRight">The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more. <br /></td></tr>
104+
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
105+
</table>
106+
</div><!-- contents -->
107+
<!-- HTML footer for doxygen 1.9.1-->
108+
<!-- start footer part -->
109+
<hr class="footer"/><address class="footer"><small>
110+
Generated on Tue Aug 19 2025 12:06:45 for xtd by <a href="https://gammasoft71.wixsite.com/gammasoft">Gammasoft</a>. All rights reserved.
111+
</small></address>
112+
</body>
113+
</html>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5+
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6+
<title>xtd: xtd.core/include/xtd/internal/__array_definition.hpp Source File</title>
7+
<link href="favicon.png" rel="shortcut icon" type="image/png"/>
8+
<link href="tabs.css" rel="stylesheet" type="text/css"/>
9+
<script type="text/javascript" src="jquery.js"></script>
10+
<script type="text/javascript" src="dynsections.js"></script>
11+
<link href="search/search.css" rel="stylesheet" type="text/css"/>
12+
<script type="text/javascript" src="search/searchdata.js"></script>
13+
<script type="text/javascript" src="search/search.js"></script>
14+
<link href="doxygen.css" rel="stylesheet" type="text/css" />
15+
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
16+
<link href="custom_images.css" rel="stylesheet" type="text/css"/>
17+
<script type="text/javascript" src="doxygen-awesome-darkmode-toggle.js"></script>
18+
<script type="text/javascript"> DoxygenAwesomeDarkModeToggle.init() </script>
19+
</head>
20+
<body>
21+
<div id="page_container">
22+
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
23+
<div id="titlearea">
24+
<table cellspacing="0" cellpadding="0" style="width: 100%;">
25+
<tbody>
26+
<tr>
27+
<td id="projectlogo">
28+
<a href="https://gammasoft71.github.io/xtd/" target="_new">
29+
<img alt="Logo" src="xtd_doxygen.png"/>
30+
</a>
31+
</td>
32+
<td id="projectalign" style="padding-left: 0.5em; text-align: right;">
33+
<div id="projectname">xtd
34+
<span id="projectnumber">0.2.0</span>
35+
</div>
36+
</td>
37+
</tr>
38+
</tbody>
39+
</table>
40+
</div>
41+
<!-- end header part -->
42+
<!-- Generated by Doxygen 1.9.7 -->
43+
<script type="text/javascript">
44+
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
45+
var searchBox = new SearchBox("searchBox", "search/",'.html');
46+
/* @license-end */
47+
</script>
48+
<script type="text/javascript" src="menudata.js"></script>
49+
<script type="text/javascript" src="menu.js"></script>
50+
<script type="text/javascript">
51+
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
52+
$(function() {
53+
initMenu('',true,false,'search.php','Search');
54+
$(document).ready(function() { init_search(); });
55+
});
56+
/* @license-end */
57+
</script>
58+
<div id="main-nav"></div>
59+
<!-- window showing the filter options -->
60+
<div id="MSearchSelectWindow"
61+
onmouseover="return searchBox.OnSearchSelectShow()"
62+
onmouseout="return searchBox.OnSearchSelectHide()"
63+
onkeydown="return searchBox.OnSearchSelectKey(event)">
64+
</div>
65+
66+
<!-- iframe showing the search results (closed by default) -->
67+
<div id="MSearchResultsWindow">
68+
<div id="MSearchResults">
69+
<div class="SRPage">
70+
<div id="SRIndex">
71+
<div id="SRResults"></div>
72+
<div class="SRStatus" id="Loading">Loading...</div>
73+
<div class="SRStatus" id="Searching">Searching...</div>
74+
<div class="SRStatus" id="NoMatches">No Matches</div>
75+
</div>
76+
</div>
77+
</div>
78+
</div>
79+
80+
<div id="nav-path" class="navpath">
81+
<ul>
82+
<li class="navelem"><a class="el" href="dir_dc97fa897e7997e4ee808021e868856c.html">xtd.core</a></li><li class="navelem"><a class="el" href="dir_cd4d13b1160eb35a323b5c83cf3e9e5e.html">include</a></li><li class="navelem"><a class="el" href="dir_8bddd848f68e3e28b5aa5e234df2e4b1.html">xtd</a></li><li class="navelem"><a class="el" href="dir_618e153bd4f02720ed2e807a9fe886a0.html">internal</a></li> </ul>
83+
</div>
84+
</div><!-- top -->
85+
<div class="header">
86+
<div class="headertitle"><div class="title">__array_definition.hpp</div></div>
87+
</div><!--header-->
88+
<div class="contents">
89+
<a href="____array__definition_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
90+
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span><span class="preprocessor">#pragma once</span></div>
91+
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span><span class="preprocessor">#if !defined(__XTD_CORE_INTERNAL__)</span></div>
92+
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="preprocessor">#error &quot;Do not include this file: Internal use only&quot;</span></div>
93+
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span><span class="preprocessor">#endif</span></div>
94+
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span><span class="preprocessor">#include &quot;../collections/generic/helpers/allocator.hpp&quot;</span></div>
95+
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span><span class="preprocessor">#include &quot;../size.hpp&quot;</span></div>
96+
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span><span class="preprocessor">#include &lt;vector&gt;</span> <span class="comment">// @todo remove line</span></div>
97+
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span> </div>
98+
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespacextd.html">xtd</a> {</div>
99+
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> <span class="keyword">template</span>&lt;<span class="keyword">class</span> type_t = std::<span class="keywordtype">nullptr</span>_t, xtd::size rank_size = 1, <span class="keyword">class</span> allocator_t = xtd::collections::<span class="keyword">generic</span>::helpers::allocator&lt;type_t&gt;&gt;</div>
100+
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> <span class="keyword">class </span>array;</div>
101+
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> </div>
102+
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> <span class="keyword">template</span>&lt;<span class="keyword">class</span> type_t, <span class="keyword">class</span> allocator_t&gt;</div>
103+
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> <span class="keyword">class </span>basic_array;</div>
104+
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> </div>
105+
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> <span class="keyword">class </span>array_abstract_object;</div>
106+
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span>}</div>
107+
<div class="ttc" id="anamespacextd_html"><div class="ttname"><a href="namespacextd.html">xtd</a></div><div class="ttdoc">The xtd namespace contains all fundamental classes to access Hardware, Os, System,...</div><div class="ttdef"><b>Definition</b> abstract.hpp:8</div></div>
108+
</div><!-- fragment --></div><!-- contents -->
109+
<!-- HTML footer for doxygen 1.9.1-->
110+
<!-- start footer part -->
111+
<hr class="footer"/><address class="footer"><small>
112+
Generated on Tue Aug 19 2025 12:06:43 for xtd by <a href="https://gammasoft71.wixsite.com/gammasoft">Gammasoft</a>. All rights reserved.
113+
</small></address>
114+
</body>
115+
</html>

0 commit comments

Comments
 (0)