{"id":12857,"date":"2022-11-21T10:25:58","date_gmt":"2022-11-21T10:25:58","guid":{"rendered":"https:\/\/digitalgateamg.com\/?p=12857"},"modified":"2022-11-24T13:00:32","modified_gmt":"2022-11-24T13:00:32","slug":"type-erasure","status":"publish","type":"post","link":"https:\/\/digitalgateamg.com\/de\/blog\/2022\/11\/21\/type-erasure\/","title":{"rendered":"Type erasure in C++"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"12857\" class=\"elementor elementor-12857\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-20e59ec elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"20e59ec\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-fb398a5\" data-id=\"fb398a5\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a0f5390 elementor-widget elementor-widget-heading\" data-id=\"a0f5390\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"> What is it?<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eb6d636 elementor-widget elementor-widget-text-editor\" data-id=\"eb6d636\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Type erasure is the technique used to hide the type meta-data of some data. When we store and manage data in such a way, the compiler is no longer to guess the type of that blob of data.<\/p><p>As an example when we cast some data type into <strong>__void *__<\/strong>, we are doing type erasure. After we pass the data through <strong>__void *__<\/strong> the compiler will no longer be able to deduce the type of data pointed by it.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7840e12 elementor-widget elementor-widget-heading\" data-id=\"7840e12\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Why and how?<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7a4883f elementor-widget elementor-widget-text-editor\" data-id=\"7a4883f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>First, let&#8217;s get to the why.<\/p><ul><li>Have you ever used a function that has to get any possible type?<\/li><li>Have you ever used a container that had to contain any possible type?<\/li><\/ul><p>The answer is most likely yes, even if you don&#8217;t remember it! If you ever used <strong>__pthread__<\/strong>, <strong>__std::thread__<\/strong>, <strong>__std::function__<\/strong>, <strong>__std::variant__<\/strong> or ultimately <strong>__std::any__<\/strong> then the answer is YES!<\/p><p>So What is common here leading us to use the same pattern?<\/p><h4><span style=\"color: #2f5aae; font-weight: bold;\">Why?<\/span><span style=\"font-weight: bold;\"><br \/><\/span><\/h4><p><span style=\"font-weight: bold;\">Polymorphism<\/span> is the answer. In polymorphism, we tread a range of different data in the same way regardless of their detailed implementation. One form of type erasure is when we use inheritance to implement polymorphism.<\/p><p>The moment we pass the address of the derived class to a pointer (or reference) of the base class, we are discarding some type of info about properties specific to the derived class and from there on, the compiler is not able to deduce them. It can only deduce the type of data it saved for runtime (with vtables, etc). And it did so only because through the use of inheritance keywords we guaranteed that they will all have it.<\/p><h4><span style=\"font-weight: bold; color: #2f5aae;\">How?\u00a0<\/span>\u00a0<\/h4><p>Let&#8217;s consider the most basic form of type erasure: Passing as a void pointer.<\/p><p>First, let&#8217;s see what is it supposed to do. Easy! It helps us contain and pass around any type we desire. Now let&#8217;s address its shortcomings and solve them.<\/p><ol><li>Type safety is broken<\/li><li>Memory safety is threatened<\/li><li>We actually have no way of checking if the type we are casting is the type we have received<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8ac6a13 elementor-widget elementor-widget-heading\" data-id=\"8ac6a13\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">\u00a01. Type safety<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5ca3cc2 elementor-widget elementor-widget-code-highlight\" data-id=\"5ca3cc2\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class foo\r\n{\r\nprivate:\r\n    int Id;\r\n    \r\n    ...\r\n};<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c2b0387 elementor-widget elementor-widget-text-editor\" data-id=\"c2b0387\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tThen we have a function that is supposed to receive any type with a void pointer:\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0c8c205 elementor-widget elementor-widget-code-highlight\" data-id=\"0c8c205\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>void bar(void * Argument)\r\n{\r\n    \/* Here we are breaking the type safety *\/\r\n\r\n    static_cast<foo *>(Argument) ...\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-42dec9f elementor-widget elementor-widget-text-editor\" data-id=\"42dec9f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here, instead of passing an instance of foo, if we pass any other type, what will happen? The compiler will not be able to detect and prevent us from doing so and we will most likely cause some form of runtime error. In another word, we broke the guarantee of safely using types. Because we can easily, cast any type to any other one in <strong>__bar__<\/strong> function and if we do it wrong, there is no way we can know until we get some exceptions in runtime.<\/p><p>So what we want is to be able to check if we are casting the pointer to the right type. If not, prevent us from using it through some exceptions later on.<\/p><p>The mechanism for runtime info in c++ is through <strong>__typeid__<\/strong> keyword.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2052ea2 elementor-widget elementor-widget-code-highlight\" data-id=\"2052ea2\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>std::type_info const &Info = typeid(int);\r\n\r\nchar const * Name = Info.name();\r\nsize_t Hash = Info.hash_code();<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c64b968 elementor-widget elementor-widget-text-editor\" data-id=\"c64b968\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><strong>type_info<\/strong> structure for each type is built during compile as static const and\u00a0<strong>typeid\u00a0<\/strong>only return a const reference to it. The only function we care about right now is<strong>\u00a0__hash_code__<\/strong>. It returns the hash of its name (it is a little bit different than the name we use).<\/p><p>We can use it to store type info alongside data. Later on, we can use it to verify if we are doing the right cast or not. Notice that we cannot use this type of info to know what type to cast to. However, we can use it to know if a certain cast is allowed.<\/p><p>To do so properly, we need to create a container first, let&#8217;s call it <strong>__Any__ <\/strong>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ff49f3e elementor-widget elementor-widget-code-highlight\" data-id=\"ff49f3e\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class Any\r\n{\r\nprivate:\r\n    void * Object = nullptr;\r\n    size_t Hash = 0;\r\n};<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-75a939d elementor-widget elementor-widget-heading\" data-id=\"75a939d\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">So let's put all of what we know together and solve the second problem:<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c03965 elementor-widget elementor-widget-code-highlight\" data-id=\"8c03965\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class Any\r\n{\r\nprivate:\r\n    void * Object = nullptr;\r\n    size_t Hash = 0;\r\n\r\npublic:\r\n    template <typename T>\r\n    inline T * Cast()\r\n    {\r\n        \/* Ensure type safety *\/\r\n        if(typeid(T).hash_code() != Hash)\r\n            throw std::bad_cast();\r\n\r\n        return reinterpret_cast<T *>(Object);\r\n    }\r\n};<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-271eb4c elementor-widget elementor-widget-text-editor\" data-id=\"271eb4c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now we actually need to store the object itself in the container. To do so we need to use dynamic memory (heap) since the size of the object is unknown to us. Here again, we take advantage of templates and we use perfect forwarding to do it with the least amount of copying.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1411afb elementor-widget elementor-widget-code-highlight\" data-id=\"1411afb\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>...\r\npublic:\r\n   template<typename T>\r\n   Any(T&&t): Object(new T(std::forward<T>(t))), Hash(typeid(T).hash_code()){}\r\n\r\n...<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a9b9315 elementor-widget elementor-widget-text-editor\" data-id=\"a9b9315\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>If we take a close look we see that the third issue is automatically fixed as well.<\/p><p>Here we encounter the second problem:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8ad914f elementor-widget elementor-widget-heading\" data-id=\"8ad914f\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">\u00a02. Memory safety<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f39864e elementor-widget elementor-widget-text-editor\" data-id=\"f39864e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now that we contain the object and can access it in a type-safe manner, we have to find a workaround for the memory problem. Since here we are storing a void pointer when our object goes out of scope, the resource tied to it will be left dangling without the destructor being called and we get memory leak problems especially if the object owns some heap memory chunks. The obvious idea that comes to mind is: can&#8217;t we just store the address to its destructor in a function pointer and call it later on like below?<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fc6ed52 elementor-widget elementor-widget-code-highlight\" data-id=\"fc6ed52\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>void (*Destructor)(void*) = &T::~T;<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-24b2d4e elementor-widget elementor-widget-text-editor\" data-id=\"24b2d4e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The problem is that constructors and destructors are special functions and during the compilation, they might be inlined, I.e. they might not exist in the binary! therefore we cannot take their address and store it in a function pointer because they might not exist in runtime!<\/p><p>The solution lies in C++ Lambda expressions also known as the swiss army knife of C++.<\/p><p>C++ Lambdas has so many properties that help solve a lot of hard problems in C++ in a dynamic way. The one we are interested right now is the fact that lambda expressions with an empty capture, can decay to function pointers or in other words, are just normal functions:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c2e95cb elementor-widget elementor-widget-code-highlight\" data-id=\"c2e95cb\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>void (*FunctionPointer)() = [](){ std::cout << \"Hello world\\n\"; };<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5a27b81 elementor-widget elementor-widget-text-editor\" data-id=\"5a27b81\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We might not be able to get the address of the destructor but we can force the compiler to create a function like our object&#8217;s destructor like this:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e43d33e elementor-widget elementor-widget-code-highlight\" data-id=\"e43d33e\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard word-wrap\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>void (*Destructor)(void const *) = [](void const * Object){ delete static_cast<T const *>(Object); };\r\n\r\n\/* And later on in the destructor *\/\r\n\r\n...\r\n    ~Any()\r\n    {\r\n        if (Destructor)\r\n        {\r\n            Destructor(Object);\r\n            Destructor = nullptr;\r\n        }\r\n    }\r\n...<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5758609 elementor-widget elementor-widget-text-editor\" data-id=\"5758609\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now we can call this function pointer on destruction to call the object&#8217;s destructor and free up the memory it occupied at the same time.<\/p><p>One thing that you have probably noticed is casting to const void pointer and you might ask since we are mutating the object won&#8217;t we get an error? Well, no! Because if so, how do const objects in your normal code clean up their resource when they go out of scope? As said before, constructor and destructors are special functions so the const qualifier actually mean different things to them.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b30685b elementor-widget elementor-widget-heading\" data-id=\"b30685b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">So let's put all of what we know together and solve the second problem:<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b41c961 elementor-widget elementor-widget-code-highlight\" data-id=\"b41c961\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard word-wrap\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class Any\r\n{\r\nprivate:\r\n    void * Object = nullptr;\r\n    void (*Destructor)(void const *) = nullptr;\r\n    size_t Hash = 0;\r\n\r\npublic:\r\n    template<typename T>\r\n    Any(T&& t) : Object(new T(std::forward<T>(t))),\r\n                 Destructor([](void const * Object){ delete static_cast<T const *>(Object); }),\r\n                 Hash(typeid(T).hash_code()) {}\r\n\r\n    ~Any()\r\n    {\r\n        if (Destructor)\r\n        {\r\n            Destructor(Object);\r\n            Destructor = nullptr;\r\n        }\r\n    }\r\n\r\n    template <typename T>\r\n    inline T * Cast()\r\n    {\r\n        \/* Ensure type safety *\/\r\n        if(typeid(T).hash_code() != Hash)\r\n            throw std::bad_cast();\r\n\r\n        return reinterpret_cast<T *>(Object);\r\n    }\r\n};<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-04b87c4 elementor-widget elementor-widget-text-editor\" data-id=\"04b87c4\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now, with the help of type erasure, we have a very basic container capable of containing any type we pass it. We can, later on, expand on it and add functionality.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6502479 elementor-widget elementor-widget-heading\" data-id=\"6502479\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">\u00a03. Standard containers<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-63df1b2 elementor-widget elementor-widget-text-editor\" data-id=\"63df1b2\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>There are a lot of standard C++ containers which use type erasure in different ways to achieve different results. Some of them are listed below:<\/p><ul><li><strong>std::function &#8211;\u00a0<\/strong> Will contain any type having a call operator with the requested signature<\/li><li><strong>std::variant<\/strong> &#8211; Will contain one of the types specified in the template<\/li><li><strong>std::any<\/strong> &#8211; Will contain any type<\/li><\/ul><p>Note that all these containers have some limitations on the types they can get. For example or container can work if this line works:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c6a6a7 elementor-widget elementor-widget-code-highlight\" data-id=\"8c6a6a7\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard word-wrap\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>`template<typename T>\r\n    Any(T&& t) : Object(new T(std::forward<T>(t))), ...<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-876885b elementor-widget elementor-widget-text-editor\" data-id=\"876885b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>I.e. if the object is either move constructible or copy constructible, based on the type passed in the construction time of our container. You can find the limitations for standard containers online.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-33c0576 elementor-widget elementor-widget-heading\" data-id=\"33c0576\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">\u00a03. Conclusion<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d5b51a4 elementor-widget elementor-widget-text-editor\" data-id=\"d5b51a4\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Type erasure is a very useful technique that can add flexibility to our code. A lot of standard containers use this technique. We started from the simplest form, briefly explored it with inheritance, and implemented our container. We can enforce different limitations to these containers to only contain some pre-specified types of objects.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-6d6cf34 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"6d6cf34\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-narrow\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a8c493e\" data-id=\"a8c493e\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-ee83ee5 elementor-widget elementor-widget-spacer\" data-id=\"ee83ee5\" data-element_type=\"widget\" data-widget_type=\"spacer.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-spacer\">\n\t\t\t<div class=\"elementor-spacer-inner\"><\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-35fc86e elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"35fc86e\" data-element_type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6ccb616 elementor-widget elementor-widget-heading\" data-id=\"6ccb616\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Weitere Artikel anschauen:<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c19d193 elementor-grid-3 elementor-grid-tablet-2 elementor-grid-mobile-1 elementor-posts--thumbnail-top elementor-widget elementor-widget-posts\" data-id=\"c19d193\" data-element_type=\"widget\" data-settings=\"{&quot;classic_row_gap&quot;:{&quot;unit&quot;:&quot;px&quot;,&quot;size&quot;:20,&quot;sizes&quot;:[]},&quot;pagination_type&quot;:&quot;numbers&quot;,&quot;classic_row_gap_tablet&quot;:{&quot;unit&quot;:&quot;px&quot;,&quot;size&quot;:30,&quot;sizes&quot;:[]},&quot;classic_columns&quot;:&quot;3&quot;,&quot;classic_columns_tablet&quot;:&quot;2&quot;,&quot;classic_columns_mobile&quot;:&quot;1&quot;,&quot;classic_row_gap_mobile&quot;:{&quot;unit&quot;:&quot;px&quot;,&quot;size&quot;:&quot;&quot;,&quot;sizes&quot;:[]}}\" data-widget_type=\"posts.classic\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-posts-container elementor-posts elementor-posts--skin-classic elementor-grid\" role=\"list\">\n\t\t\t\t<article class=\"elementor-post elementor-grid-item post-14657 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized tag-accelerator-pedal-simulator tag-acoustic-tuning tag-automotive-industry tag-digitalgate tag-embedded-system-development tag-hardware-development tag-software-development\" role=\"listitem\">\n\t\t\t\t<a class=\"elementor-post__thumbnail__link\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/09\/10\/accelerator-pedal-simulator-for-acoustics-tuning\/\" tabindex=\"-1\" >\n\t\t\t<div class=\"elementor-post__thumbnail\"><img fetchpriority=\"high\" decoding=\"async\" width=\"930\" height=\"620\" src=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/09\/Accelerator-Pedal-Simulator-for-Acoustic-Tuning-1-930x620.png\" class=\"attachment-neve-blog size-neve-blog wp-image-14672\" alt=\"\" \/><\/div>\n\t\t<\/a>\n\t\t\t\t<div class=\"elementor-post__text\">\n\t\t\t\t<h3 class=\"elementor-post__title\">\n\t\t\t<a href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/09\/10\/accelerator-pedal-simulator-for-acoustics-tuning\/\" >\n\t\t\t\tAccelerator Pedal Simulator for Acoustics Tuning\t\t\t<\/a>\n\t\t<\/h3>\n\t\t\t\t<div class=\"elementor-post__meta-data\">\n\t\t\t\t\t<span class=\"elementor-post-date\">\n\t\t\tSeptember 10, 2024\t\t<\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-post__excerpt\">\n\t\t\t<p>Have you ever wondered how the perfect roar of an engine, or the smooth hum of a luxury car is crafted? It all comes<\/p>\n\t\t<\/div>\n\t\t\t\t\t<div class=\"elementor-post__read-more-wrapper\">\n\t\t\n\t\t<a class=\"elementor-post__read-more\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/09\/10\/accelerator-pedal-simulator-for-acoustics-tuning\/\" aria-label=\"Mehr \u00fcber Accelerator Pedal Simulator for Acoustics Tuning\" tabindex=\"-1\" >\n\t\t\tRead More \u00bb\t\t<\/a>\n\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/article>\n\t\t\t\t<article class=\"elementor-post elementor-grid-item post-14620 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized tag-condition-monitoring tag-data-acquisition-system tag-embedded-system-development tag-hardware-development tag-predictive-maintenance tag-software-development\" role=\"listitem\">\n\t\t\t\t<a class=\"elementor-post__thumbnail__link\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/08\/28\/industrial-data-acquisition-system\/\" tabindex=\"-1\" >\n\t\t\t<div class=\"elementor-post__thumbnail\"><img decoding=\"async\" width=\"930\" height=\"620\" src=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/08\/IEPE_DAS-930x620.png\" class=\"attachment-neve-blog size-neve-blog wp-image-14649\" alt=\"Data Acquistion PCB board with DigitalGate logo on a gray background\" \/><\/div>\n\t\t<\/a>\n\t\t\t\t<div class=\"elementor-post__text\">\n\t\t\t\t<h3 class=\"elementor-post__title\">\n\t\t\t<a href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/08\/28\/industrial-data-acquisition-system\/\" >\n\t\t\t\tIndustrial Data Acquisition System\t\t\t<\/a>\n\t\t<\/h3>\n\t\t\t\t<div class=\"elementor-post__meta-data\">\n\t\t\t\t\t<span class=\"elementor-post-date\">\n\t\t\tAugust 28, 2024\t\t<\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-post__excerpt\">\n\t\t\t<p>We&#8217;re excited to unveil one of our flagship products: an efficient and secure Data Acquisition System (DAS). Our team has designed this solution to<\/p>\n\t\t<\/div>\n\t\t\t\t\t<div class=\"elementor-post__read-more-wrapper\">\n\t\t\n\t\t<a class=\"elementor-post__read-more\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/08\/28\/industrial-data-acquisition-system\/\" aria-label=\"Mehr \u00fcber Industrial Data Acquisition System\" tabindex=\"-1\" >\n\t\t\tRead More \u00bb\t\t<\/a>\n\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/article>\n\t\t\t\t<article class=\"elementor-post elementor-grid-item post-14267 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized\" role=\"listitem\">\n\t\t\t\t<a class=\"elementor-post__thumbnail__link\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/03\/15\/optimizing-our-custom-motor-controller-for-motion-control\/\" tabindex=\"-1\" >\n\t\t\t<div class=\"elementor-post__thumbnail\"><img decoding=\"async\" width=\"928\" height=\"620\" src=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/03\/background-blog-BMS-928x620.jpeg\" class=\"attachment-neve-blog size-neve-blog wp-image-14268\" alt=\"\" srcset=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/03\/background-blog-BMS-928x620.jpeg 928w, https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/03\/background-blog-BMS-18x12.jpeg 18w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><\/div>\n\t\t<\/a>\n\t\t\t\t<div class=\"elementor-post__text\">\n\t\t\t\t<h3 class=\"elementor-post__title\">\n\t\t\t<a href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/03\/15\/optimizing-our-custom-motor-controller-for-motion-control\/\" >\n\t\t\t\tOptimizing our Custom Motor Controller for Motion Control\t\t\t<\/a>\n\t\t<\/h3>\n\t\t\t\t<div class=\"elementor-post__meta-data\">\n\t\t\t\t\t<span class=\"elementor-post-date\">\n\t\t\tM\u00e4rz 15, 2024\t\t<\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-post__excerpt\">\n\t\t\t<p>Using our carefully designed board, we demonstrate the impressive power and flexibility of integrating modern technologies into motor controllers. In the realm of small<\/p>\n\t\t<\/div>\n\t\t\t\t\t<div class=\"elementor-post__read-more-wrapper\">\n\t\t\n\t\t<a class=\"elementor-post__read-more\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/03\/15\/optimizing-our-custom-motor-controller-for-motion-control\/\" aria-label=\"Mehr \u00fcber Optimizing our Custom Motor Controller for Motion Control\" tabindex=\"-1\" >\n\t\t\tRead More \u00bb\t\t<\/a>\n\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/article>\n\t\t\t\t<article class=\"elementor-post elementor-grid-item post-14259 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized\" role=\"listitem\">\n\t\t\t\t<a class=\"elementor-post__thumbnail__link\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/03\/01\/what-it-means-to-make-an-efficient-battery-management-system\/\" tabindex=\"-1\" >\n\t\t\t<div class=\"elementor-post__thumbnail\"><img loading=\"lazy\" decoding=\"async\" width=\"928\" height=\"620\" src=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/03\/Background-1-928x620.jpeg\" class=\"attachment-neve-blog size-neve-blog wp-image-14255\" alt=\"\" srcset=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/03\/Background-1-928x620.jpeg 928w, https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/03\/Background-1-18x12.jpeg 18w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><\/div>\n\t\t<\/a>\n\t\t\t\t<div class=\"elementor-post__text\">\n\t\t\t\t<h3 class=\"elementor-post__title\">\n\t\t\t<a href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/03\/01\/what-it-means-to-make-an-efficient-battery-management-system\/\" >\n\t\t\t\tWhat it means to make an efficient Battery Management System?\t\t\t<\/a>\n\t\t<\/h3>\n\t\t\t\t<div class=\"elementor-post__meta-data\">\n\t\t\t\t\t<span class=\"elementor-post-date\">\n\t\t\tM\u00e4rz 1, 2024\t\t<\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-post__excerpt\">\n\t\t\t<p>Digital Gate is excited to introduce you to one of our flagship products: an efficient and secure Battery Management System (BMS), meticulously designed and<\/p>\n\t\t<\/div>\n\t\t\t\t\t<div class=\"elementor-post__read-more-wrapper\">\n\t\t\n\t\t<a class=\"elementor-post__read-more\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/03\/01\/what-it-means-to-make-an-efficient-battery-management-system\/\" aria-label=\"Mehr \u00fcber What it means to make an efficient Battery Management System?\" tabindex=\"-1\" >\n\t\t\tRead More \u00bb\t\t<\/a>\n\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/article>\n\t\t\t\t<article class=\"elementor-post elementor-grid-item post-14236 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized\" role=\"listitem\">\n\t\t\t\t<a class=\"elementor-post__thumbnail__link\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/02\/21\/embedded-world-2024\/\" tabindex=\"-1\" >\n\t\t\t<div class=\"elementor-post__thumbnail\"><img loading=\"lazy\" decoding=\"async\" width=\"928\" height=\"620\" src=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/02\/EW24-Thumbnail-1-928x620.png\" class=\"attachment-neve-blog size-neve-blog wp-image-14239\" alt=\"\" srcset=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/02\/EW24-Thumbnail-1-928x620.png 928w, https:\/\/digitalgateamg.com\/wp-content\/uploads\/2024\/02\/EW24-Thumbnail-1-18x12.png 18w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><\/div>\n\t\t<\/a>\n\t\t\t\t<div class=\"elementor-post__text\">\n\t\t\t\t<h3 class=\"elementor-post__title\">\n\t\t\t<a href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/02\/21\/embedded-world-2024\/\" >\n\t\t\t\tEmbedded World 2024\t\t\t<\/a>\n\t\t<\/h3>\n\t\t\t\t<div class=\"elementor-post__meta-data\">\n\t\t\t\t\t<span class=\"elementor-post-date\">\n\t\t\tFebruar 21, 2024\t\t<\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-post__excerpt\">\n\t\t\t<p>DigitalGate is excited to announce its forthcoming participation at Embedded World 2024 taking place in Nuremberg from the 9th to the 11th of April.<\/p>\n\t\t<\/div>\n\t\t\t\t\t<div class=\"elementor-post__read-more-wrapper\">\n\t\t\n\t\t<a class=\"elementor-post__read-more\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2024\/02\/21\/embedded-world-2024\/\" aria-label=\"Mehr \u00fcber Embedded World 2024\" tabindex=\"-1\" >\n\t\t\tRead More \u00bb\t\t<\/a>\n\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/article>\n\t\t\t\t<article class=\"elementor-post elementor-grid-item post-13342 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized\" role=\"listitem\">\n\t\t\t\t<a class=\"elementor-post__thumbnail__link\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2023\/08\/08\/capacitance-preservation-strategies-for-dc-bias-in-mlccs\/\" tabindex=\"-1\" >\n\t\t\t<div class=\"elementor-post__thumbnail\"><img loading=\"lazy\" decoding=\"async\" width=\"930\" height=\"620\" src=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2023\/08\/blog-info-new-e1691567543143-930x620.png\" class=\"attachment-neve-blog size-neve-blog wp-image-13420\" alt=\"\" \/><\/div>\n\t\t<\/a>\n\t\t\t\t<div class=\"elementor-post__text\">\n\t\t\t\t<h3 class=\"elementor-post__title\">\n\t\t\t<a href=\"https:\/\/digitalgateamg.com\/de\/blog\/2023\/08\/08\/capacitance-preservation-strategies-for-dc-bias-in-mlccs\/\" >\n\t\t\t\tKapazit\u00e4tserhalt: Strategien f\u00fcr DC-Vorspannung in MLCCs\t\t\t<\/a>\n\t\t<\/h3>\n\t\t\t\t<div class=\"elementor-post__meta-data\">\n\t\t\t\t\t<span class=\"elementor-post-date\">\n\t\t\tAugust 8, 2023\t\t<\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-post__excerpt\">\n\t\t\t<p>Ist die Kapazit\u00e4t des Kondensators immer gleich? Keramische Vielschichtkondensatoren (Multilayer Ceramic Capacitors, MLCCs) bieten eine Reihe von Vorteilen,<\/p>\n\t\t<\/div>\n\t\t\t\t\t<div class=\"elementor-post__read-more-wrapper\">\n\t\t\n\t\t<a class=\"elementor-post__read-more\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2023\/08\/08\/capacitance-preservation-strategies-for-dc-bias-in-mlccs\/\" aria-label=\"Mehr \u00fcber Capacitance Preservation: Strategies for DC Bias in MLCCs\" tabindex=\"-1\" >\n\t\t\tRead More \u00bb\t\t<\/a>\n\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/article>\n\t\t\t\t<\/div>\n\t\t\n\t\t\t\t<div class=\"e-load-more-anchor\" data-page=\"1\" data-max-page=\"4\" data-next-page=\"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/posts\/12857\/page\/2\/\"><\/div>\n\t\t\t\t<nav class=\"elementor-pagination\" aria-label=\"Seitennummerierung\">\n\t\t\t<span aria-current=\"page\" class=\"page-numbers current\"><span class=\"elementor-screen-only\">Seite<\/span>1<\/span>\n<a class=\"page-numbers\" href=\"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/posts\/12857\/page\/2\/\"><span class=\"elementor-screen-only\">Seite<\/span>2<\/a>\n<a class=\"page-numbers\" href=\"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/posts\/12857\/page\/3\/\"><span class=\"elementor-screen-only\">Seite<\/span>3<\/a>\n<a class=\"page-numbers\" href=\"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/posts\/12857\/page\/4\/\"><span class=\"elementor-screen-only\">Seite<\/span>4<\/a>\t\t<\/nav>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>What is it? Type erasure is the technique used to hide the type meta-data of some data. When we store and manage data in such a way, the compiler is no longer to guess the type of that blob of data. As an example when we cast some data type into __void *__, we are&hellip;&nbsp;<a href=\"https:\/\/digitalgateamg.com\/de\/blog\/2023\/08\/08\/capacitance-preservation-strategies-for-dc-bias-in-mlccs\/\" class=\"\" rel=\"bookmark\">Weiterlesen &raquo;<span class=\"screen-reader-text\">Kapazit\u00e4tserhalt: Strategien f\u00fcr DC-Vorspannung in MLCCs<\/span><\/a><\/p>","protected":false},"author":12,"featured_media":12943,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"coauthors":[],"class_list":["post-12857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.1 (Yoast SEO v26.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Type erasure in C++ - DigitalGate Custom Electronics<\/title>\n<meta name=\"description\" content=\"Type erasure is a technique used to hide the type meta-data of some data. Learn more about it in C++, type and memory safety and containers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/digitalgateamg.com\/de\/blog\/2022\/11\/21\/type-erasure\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Type erasure in C++\" \/>\n<meta property=\"og:description\" content=\"Type erasure is a technique used to hide the type meta-data of some data. Learn more about it in C++, type and memory safety and containers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/digitalgateamg.com\/de\/blog\/2022\/11\/21\/type-erasure\/\" \/>\n<meta property=\"og:site_name\" content=\"DigitalGate Custom Electronics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DigitalGateamg\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-21T10:25:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-24T13:00:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png\" \/>\n\t<meta property=\"og:image:width\" content=\"938\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Digital Gate\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Digital Gate\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"7\u00a0Minuten\" \/>\n\t<meta name=\"twitter:label3\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data3\" content=\"Digital Gate\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/\"},\"author\":{\"name\":\"Digital Gate\",\"@id\":\"https:\/\/digitalgateamg.com\/#\/schema\/person\/27511cb01dbba51abd9b489e6adc2fce\"},\"headline\":\"Type erasure in C++\",\"datePublished\":\"2022-11-21T10:25:58+00:00\",\"dateModified\":\"2022-11-24T13:00:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/\"},\"wordCount\":1287,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/digitalgateamg.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png\",\"articleSection\":[\"Uncategorized\"],\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/\",\"url\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/\",\"name\":\"Type erasure in C++ - DigitalGate Custom Electronics\",\"isPartOf\":{\"@id\":\"https:\/\/digitalgateamg.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png\",\"datePublished\":\"2022-11-21T10:25:58+00:00\",\"dateModified\":\"2022-11-24T13:00:32+00:00\",\"description\":\"Type erasure is a technique used to hide the type meta-data of some data. Learn more about it in C++, type and memory safety and containers.\",\"breadcrumb\":{\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage\",\"url\":\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png\",\"contentUrl\":\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png\",\"width\":938,\"height\":628},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/digitalgateamg.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Type erasure in C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/digitalgateamg.com\/#website\",\"url\":\"https:\/\/digitalgateamg.com\/\",\"name\":\"DigitalGate Custom Electronics\",\"description\":\"Embedded Software and Hardware Solutions\",\"publisher\":{\"@id\":\"https:\/\/digitalgateamg.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/digitalgateamg.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/digitalgateamg.com\/#organization\",\"name\":\"DigitalGate Amg S.A.\",\"url\":\"https:\/\/digitalgateamg.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/digitalgateamg.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2021\/10\/logo-firma.png\",\"contentUrl\":\"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2021\/10\/logo-firma.png\",\"width\":370,\"height\":370,\"caption\":\"DigitalGate Amg S.A.\"},\"image\":{\"@id\":\"https:\/\/digitalgateamg.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/DigitalGateamg\/\",\"https:\/\/www.linkedin.com\/company\/sc-digitalgate-amg-srl\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/digitalgateamg.com\/#\/schema\/person\/27511cb01dbba51abd9b489e6adc2fce\",\"name\":\"Digital Gate\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/digitalgateamg.com\/#\/schema\/person\/image\/74f3f186c8bd8fbf3578b2a180ed40b6\",\"url\":\"https:\/\/digitalgateamg.com\/wp-content\/litespeed\/avatar\/46f85298923a63b5939c9a06d38c2790.jpg?ver=1775037534\",\"contentUrl\":\"https:\/\/digitalgateamg.com\/wp-content\/litespeed\/avatar\/46f85298923a63b5939c9a06d38c2790.jpg?ver=1775037534\",\"caption\":\"Digital Gate\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Type erasure in C++ - DigitalGate Custom Electronics","description":"Type erasure is a technique used to hide the type meta-data of some data. Learn more about it in C++, type and memory safety and containers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/digitalgateamg.com\/de\/blog\/2022\/11\/21\/type-erasure\/","og_locale":"de_DE","og_type":"article","og_title":"Type erasure in C++","og_description":"Type erasure is a technique used to hide the type meta-data of some data. Learn more about it in C++, type and memory safety and containers.","og_url":"https:\/\/digitalgateamg.com\/de\/blog\/2022\/11\/21\/type-erasure\/","og_site_name":"DigitalGate Custom Electronics","article_publisher":"https:\/\/www.facebook.com\/DigitalGateamg\/","article_published_time":"2022-11-21T10:25:58+00:00","article_modified_time":"2022-11-24T13:00:32+00:00","og_image":[{"width":938,"height":628,"url":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png","type":"image\/png"}],"author":"Digital Gate","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Digital Gate","Gesch\u00e4tzte Lesezeit":"7\u00a0Minuten","Written by":"Digital Gate"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#article","isPartOf":{"@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/"},"author":{"name":"Digital Gate","@id":"https:\/\/digitalgateamg.com\/#\/schema\/person\/27511cb01dbba51abd9b489e6adc2fce"},"headline":"Type erasure in C++","datePublished":"2022-11-21T10:25:58+00:00","dateModified":"2022-11-24T13:00:32+00:00","mainEntityOfPage":{"@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/"},"wordCount":1287,"commentCount":0,"publisher":{"@id":"https:\/\/digitalgateamg.com\/#organization"},"image":{"@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage"},"thumbnailUrl":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png","articleSection":["Uncategorized"],"inLanguage":"de","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/","url":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/","name":"Type erasure in C++ - DigitalGate Custom Electronics","isPartOf":{"@id":"https:\/\/digitalgateamg.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage"},"image":{"@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage"},"thumbnailUrl":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png","datePublished":"2022-11-21T10:25:58+00:00","dateModified":"2022-11-24T13:00:32+00:00","description":"Type erasure is a technique used to hide the type meta-data of some data. Learn more about it in C++, type and memory safety and containers.","breadcrumb":{"@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/"]}]},{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#primaryimage","url":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png","contentUrl":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png","width":938,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/digitalgateamg.com\/blog\/2022\/11\/21\/type-erasure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/digitalgateamg.com\/"},{"@type":"ListItem","position":2,"name":"Type erasure in C++"}]},{"@type":"WebSite","@id":"https:\/\/digitalgateamg.com\/#website","url":"https:\/\/digitalgateamg.com\/","name":"DigitalGate Custom Electronics","description":"Embedded Software and Hardware Solutions","publisher":{"@id":"https:\/\/digitalgateamg.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/digitalgateamg.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"https:\/\/digitalgateamg.com\/#organization","name":"DigitalGate Amg S.A.","url":"https:\/\/digitalgateamg.com\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/digitalgateamg.com\/#\/schema\/logo\/image\/","url":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2021\/10\/logo-firma.png","contentUrl":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2021\/10\/logo-firma.png","width":370,"height":370,"caption":"DigitalGate Amg S.A."},"image":{"@id":"https:\/\/digitalgateamg.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DigitalGateamg\/","https:\/\/www.linkedin.com\/company\/sc-digitalgate-amg-srl\/"]},{"@type":"Person","@id":"https:\/\/digitalgateamg.com\/#\/schema\/person\/27511cb01dbba51abd9b489e6adc2fce","name":"Digital Gate","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/digitalgateamg.com\/#\/schema\/person\/image\/74f3f186c8bd8fbf3578b2a180ed40b6","url":"https:\/\/digitalgateamg.com\/wp-content\/litespeed\/avatar\/46f85298923a63b5939c9a06d38c2790.jpg?ver=1775037534","contentUrl":"https:\/\/digitalgateamg.com\/wp-content\/litespeed\/avatar\/46f85298923a63b5939c9a06d38c2790.jpg?ver=1775037534","caption":"Digital Gate"}}]}},"jetpack_featured_media_url":"https:\/\/digitalgateamg.com\/wp-content\/uploads\/2022\/11\/Type-erasure.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/posts\/12857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/comments?post=12857"}],"version-history":[{"count":0,"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/posts\/12857\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/media\/12943"}],"wp:attachment":[{"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/media?parent=12857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/categories?post=12857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/tags?post=12857"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digitalgateamg.com\/de\/wp-json\/wp\/v2\/coauthors?post=12857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}