<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Cpp on Shaka</title><link>https://shakaxi.github.io/tags/cpp/</link><description>Recent content in Cpp on Shaka</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 27 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://shakaxi.github.io/tags/cpp/index.xml" rel="self" type="application/rss+xml"/><item><title>Span</title><link>https://shakaxi.github.io/posts/span/</link><pubDate>Mon, 27 Apr 2026 00:00:00 +0000</pubDate><guid>https://shakaxi.github.io/posts/span/</guid><description>&lt;p&gt;&#10;&lt;em&gt;std::span&lt;/em&gt; is a class template introduced in C++ 20. As one of the most paramount features, span is essentially a non-owning view of a sequence of objects, which is contiguously distributed in memory and can consequently be iterated and indexed, e.g., &lt;code class="verbatim"&gt;std::array&lt;/code&gt;, &lt;code class="verbatim"&gt;std::vector&lt;/code&gt;, &lt;code class="verbatim"&gt;std::string&lt;/code&gt;.&lt;/p&gt;&#10;&lt;div id="outline-container-headline-1" class="outline-2"&gt;&#10;&lt;h2 id="headline-1"&gt;&#10;Constructors&#10;&lt;/h2&gt;&#10;&lt;div id="outline-text-headline-1" class="outline-text-2"&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;span(ptr)&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;span(ptr, len)&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;span(starting_ptr, ending_ptr)&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;div id="outline-container-headline-2" class="outline-2"&gt;&#10;&lt;h2 id="headline-2"&gt;&#10;Member functions&#10;&lt;/h2&gt;&#10;&lt;div id="outline-text-headline-2" class="outline-text-2"&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;first(num)&lt;/code&gt; returns a new span comprising the first &lt;code class="verbatim"&gt;num&lt;/code&gt; elements.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;last(num)&lt;/code&gt; returns a new span comprising the last &lt;code class="verbatim"&gt;num&lt;/code&gt; elements.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;front()&lt;/code&gt; / &lt;code class="verbatim"&gt;data()&lt;/code&gt; returns a reference to the first element.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;back()&lt;/code&gt; returns a reference to the last element.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;at(idx)&lt;/code&gt; / &lt;code class="verbatim"&gt;operator[idx]&lt;/code&gt; returns a reference to the &lt;code class="verbatim"&gt;idx&lt;/code&gt; th element.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;subspan(starting_idx, len)&lt;/code&gt; returns a new span of length &lt;code class="verbatim"&gt;len&lt;/code&gt; starting from &lt;code class="verbatim"&gt;starting_idx&lt;/code&gt; th element.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;size()&lt;/code&gt; returns the number of elements in the span.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;empty()&lt;/code&gt; returns a boolean indicator whether the span is empty.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;begin()&lt;/code&gt; returns the iterator to the beginning of the span.&lt;/li&gt;&#10;&lt;li&gt;&lt;code class="verbatim"&gt;end()&lt;/code&gt; returns the iterator to the ending (sentinel) of the span.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;</description></item><item><title>Armadillo</title><link>https://shakaxi.github.io/posts/armadillo/</link><pubDate>Wed, 15 Oct 2025 00:00:00 +0000</pubDate><guid>https://shakaxi.github.io/posts/armadillo/</guid><description>&lt;div id="outline-container-headline-1" class="outline-2"&gt;&#10;&lt;h2 id="headline-1"&gt;&#10;Introduction&#10;&lt;/h2&gt;&#10;&lt;div id="outline-text-headline-1" class="outline-text-2"&gt;&#10;&lt;p&gt;&lt;em&gt;Armadillo&lt;/em&gt;&lt;sup class="footnote-reference"&gt;&lt;a id="footnote-reference-1" href="#footnote-1"&gt;1&lt;/a&gt;&lt;/sup&gt; is an excellent C++ library, which provides efficient linear algebra related operations, based on a series of classes, e.g., for vectors, matrices, etc. Thanks to its friendly interfaces, similar to &lt;em&gt;MATLAB&lt;/em&gt;, the library is very easy to use.&lt;/p&gt;&#10;&lt;p&gt;&#10;Armadillo is developped by Conrad Sanderson and Ryan Curtin, and released under &lt;a href="https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)"&gt;Apache 2.0 license&lt;/a&gt;.&lt;/p&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;div id="outline-container-headline-2" class="outline-2"&gt;&#10;&lt;h2 id="headline-2"&gt;&#10;Installation &amp;amp; configuration&#10;&lt;/h2&gt;&#10;&lt;div id="outline-text-headline-2" class="outline-text-2"&gt;&#10;&lt;div id="outline-container-headline-3" class="outline-3"&gt;&#10;&lt;h3 id="headline-3"&gt;&#10;Installation&#10;&lt;/h3&gt;&#10;&lt;div id="outline-text-headline-3" class="outline-text-3"&gt;&#10;&lt;p&gt;Above all, several third-party open source libraries (including &lt;a href="https://github.com/xianyi/OpenBLAS.git"&gt;OpenBLAS&lt;/a&gt;, &lt;a href="http://www.netlib.org/lapack"&gt;LAPACK&lt;/a&gt;, &lt;a href="https://www.arpack.org"&gt;ARPACK&lt;/a&gt;, &lt;a href="https://github.com/xiaoyeli/superlu.git"&gt;SuperLU&lt;/a&gt;) should be installed as necessary dependencies. Taking ArchLinux for instance, these libraries can be simply installed by&lt;/p&gt;&#10;&lt;div class="src src-shell"&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; pacman -S openblas lapack arpack superlu&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;&#10;Then, armadillo can be installed by executing following commands.&lt;/p&gt;&#10;&lt;div class="src src-shell"&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; git clone --depth &lt;span style="color:#0550ae"&gt;1&lt;/span&gt; https://gitlab.com/conradsnicta/armadillo-code.git&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#6639ba"&gt;cd&lt;/span&gt; armadillo-code&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; cmake . -DCMAKE_INSTALL_PREFIX:PATH&lt;span style="color:#0550ae"&gt;=&lt;/span&gt;/opt/armadillo&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; make&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; make install&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;div id="outline-container-headline-4" class="outline-3"&gt;&#10;&lt;h3 id="headline-4"&gt;&#10;Configuration&#10;&lt;/h3&gt;&#10;&lt;div id="outline-text-headline-4" class="outline-text-3"&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Create file &lt;code class="verbatim"&gt;/etc/ld.so.conf.d/arma.conf&lt;/code&gt; with its content as follows.&lt;/p&gt;&#10;&lt;div class="src src-shell"&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; /opt/armadillo/lib&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Then, fresh the cache accordingly.&lt;/p&gt;&#10;&lt;div class="src src-shell"&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ldconfig&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Create a soft link for headers.&lt;/p&gt;&#10;&lt;div class="src src-shell"&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ln -s /opt/armadillo/include/* /usr/local/include/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;div id="outline-container-headline-5" class="outline-3"&gt;&#10;&lt;h3 id="headline-5"&gt;&#10;Building &amp;amp; linking&#10;&lt;/h3&gt;&#10;&lt;div id="outline-text-headline-5" class="outline-text-3"&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Due to the soft links in &lt;code class="verbatim"&gt;/usr/local/include&lt;/code&gt;, the headers can already be found.&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Due to &lt;code class="verbatim"&gt;/etc/ld.so.conf.d/arma.conf&lt;/code&gt;, the object files in the library can be directly linked by option &lt;code class="verbatim"&gt;-larmadillo&lt;/code&gt;, e.g.,&lt;/p&gt;&#10;&lt;div class="src src-shell"&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; g++ main.cpp -o main -O2 -std&lt;span style="color:#0550ae"&gt;=&lt;/span&gt;c++14 -larmadillo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;</description></item></channel></rss>