boost::compressed_pair behaves like std::pair. However, if one or both template parameters are empty classes, boost::compressed_pair consumes less memory. boost::compressed_pair uses a technique known as empty base class optimization.

  1. #include <boost/compressed_pair.hpp>
  2. #include <utility>
  3. #include <iostream>
  4.  
  5. struct empty [};
  6.  
  7. int main() {
  8. std::pair<int, empty> p;
  9. std::cout << sizeof(p) << std::endl;
  10.  
  11. boost::compressed_pair<int, empty> cp;
  12. std::cout << sizeof(cp) << std::endl;
  13.  
  14. return ;
  15. }

输出为:

8

4

There is another difference between boost::compressed_pair and std::pair. the values stored in boost::compressed_pair are accessed through the member functions first() and second(), std::pair uses two indentically named member variables instead.

boost compressedPair的更多相关文章

  1. boost强分类器的实现

    boost.cpp文件下: bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator, int _numSampl ...

  2. Boost信号/槽signals2

    信号槽是Qt框架中一个重要的部分,主要用来解耦一组互相协作的类,使用起来非常方便.项目中有同事引入了第三方的信号槽机制,其实Boost本身就有信号/槽,而且Boost的模块相对来说更稳定. signa ...

  3. 玩转Windows服务系列——使用Boost.Application快速构建Windows服务

    玩转Windows服务系列——创建Windows服务一文中,介绍了如何快速使用VS构建一个Windows服务.Debug.Release版本的注册和卸载,及其原理和服务运行.停止流程浅析分别介绍了Wi ...

  4. boost::function的用法

    本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象. 1.  介绍 Boost.Func ...

  5. Boost条件变量condition_variable_any

    Boost条件变量可以用来实现线程同步,它必须与互斥量配合使用.使用条件变量实现生产者消费者的简单例子如下,需要注意的是cond_put.wait(lock)是在等待条件满足.如果条件不满足,则释放锁 ...

  6. 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件“libboost_thread-vc140-mt-gd-1_63.lib“的解决办法

    1,到官网下载最新的boost,www.boost.org 这里我下载的1-63版本. 2,安装,解压后运行bootstrap.bat文件.稍等一小会就OK. 3,编译boost库.注意一定要使用VS ...

  7. boost.python笔记

    boost.python笔记 标签: boost.python,python, C++ 简介 Boost.python是什么? 它是boost库的一部分,随boost一起安装,用来实现C++和Pyth ...

  8. vs2013给项目统一配置boost库

    1.打开项目,然后点击菜单中的 视图->其他窗口->属性管理器 2. 打开属性管理器,点击项目前的箭头,展开项目,找到debug或者release下面的Microsoft.Cpp.Win3 ...

  9. 基于C/S架构的3D对战网络游戏C++框架 _05搭建系统开发环境与Boost智能指针、内存池初步了解

    本系列博客主要是以对战游戏为背景介绍3D对战网络游戏常用的开发技术以及C++高级编程技巧,有了这些知识,就可以开发出中小型游戏项目或3D工业仿真项目. 笔者将分为以下三个部分向大家介绍(每日更新): ...

随机推荐

  1. CSS3中哪些新属性—阴影、文本省略(1)

    CSS3中的阴影,我知道的就是盒阴影和文字阴影.两者使用大同小异. 1.文字阴影 不知道为啥阴影会被开发出来,觉得这没啥好用啊.用了之后发现好像还行,使页面更有立体感了那么一点点.看起来趣味性强一点. ...

  2. python 使用xlsxwriter的方法属性

    http://xlsxwriter.readthedocs.io/format.html

  3. Vagrant 手册之 Vagrantfile - SSH 设置 config.ssh

    原文地址 配置的命名空间:config.ssh config.ssh 中的设置与配置 Vagrant 如何通过 SSH 访问您的计算机相关. 大多数 Vagrant 设置一样,一般使用默认设置即可,但 ...

  4. canvas绘制验证码

    css样式: <style> body{ text-align: center; } canvas{ background:#ddd; } </style> body中添加标签 ...

  5. hdu6228Tree

    Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...

  6. 编程语言-Ruby-问题整理

    安装 https://github.com/oneclick/rubyinstaller2/releases/tag/RubyInstaller-2.6.0-1

  7. 20190825 On Java8 第十三章 函数式编程

    第十三章 函数式编程 函数式编程语言操纵代码片段就像操作数据一样容易. 虽然 Java 不是函数式语言,但 Java 8 Lambda 表达式和方法引用 (Method References) 允许你 ...

  8. JavaScript Tre

    function BinarySearchTree() { var Node = function(key) { this.key = key; this.left = null; this.righ ...

  9. Codeforces 1093D(染色+组合数学)

    题面 传送门 题目大意:给出一个无向图,每个节点可以填1,2,3三个数中的一个 问有多少种填数方案,使两个相邻节点的数之和为奇数 分析 如果图中有奇环,一定无解 我们对图黑白染色,由于图可能不联通,记 ...

  10. Cnblogs 的 MetaWeblog 的接口发生了变化

    Cnblogs 的 MetaWeblog 的接口发生了变化 */--> Cnblogs 的 MetaWeblog 的接口发生了变化 最近把 emacs 重新配置了一下,把 cnblogs 包也重 ...