inline

C++ Shorten subsequent function calls

六月ゝ 毕业季﹏ 提交于 2020-01-13 17:56:40
问题 I try to find a way in C++17 to shorten following function calls: GetCurrentContext()->GetEntityManager()->CreateEntity(); maybe to something like: EM()->CreateEntity(); I tried a function pointer, but this is only valid for static functions: constexpr auto &EM = GetContext()->GetEntityManager; // error: reference to non-static member function must be called; Is there a better solution than using a Macro? #define EM GetContext()->GetEntityManager When using an inline function call, i'm afraid

Code organization across files that has to deal with template functions and inlining

走远了吗. 提交于 2020-01-13 11:39:29
问题 I'm maintaining a large library of template classes that perform algebraic computations based on either float or double type. Many of the classes have accessor methods (getters and setters) and other functions that run small amounts of code, therefore such functions need to be qualified as inline when the compiler locates their definitions. Other member functions, in contrast, contain sophisticated code and thus would better be called rather than inlined. A substantial part of the function

Why is my method calling Assembly.GetCallingAssembly() not JIT-inlined?

独自空忆成欢 提交于 2020-01-13 10:53:30
问题 I'm trying to craft a short C# snippet that would illustrate change of Assembly.GetCallingAssembly() behavior because of JIT-inlining outlined in MSDN. Here's my code so far: class Program { static void Main(string[] args) { Console.WriteLine( GetAssembly().FullName ); Console.ReadLine(); } static Assembly GetAssembly() { return System.Reflection.Assembly.GetCallingAssembly(); } } which I build in "Release" and start using "Start Without Debugging" - this setup made code from this answer

Save M2M “Through” Inlines in Django Admin

限于喜欢 提交于 2020-01-13 10:28:09
问题 Apparently Django's ModelAdmin/ModelForm doesn't allow you to use save_m2m() if there's an intermediate through table for a ManyToManyField. models.py: from django.db import models def make_uuid(): import uuid return uuid.uuid4().hex class MyModel(models.Model): id = models.CharField(default=make_uuid, max_length=32, primary_key=True) title = models.CharField(max_length=32) many = models.ManyToManyField("RelatedModel", through="RelatedToMyModel") def save(self, *args, **kwargs): if not self

盒模型与布局

血红的双手。 提交于 2020-01-12 09:16:11
1.盒模型 一个元素在页面中相当于一个盒子,包括margin、border、padding、content,如下图所示: 图1 css盒子 盒子模型包括IE盒模型与标准盒模型。 div{ width: 100px; height: 50px; border: 2px; padding: 10px; margin: 20px; } 标准盒子模型: 元素所占宽度: width = margin+ border + padding + width(内容宽度), 元素所占高度height同理。 css中指定的宽度是content宽度,高度是content高度。 div实际所占的宽度width = width(content宽度) + padding-left + padding-right + border-left + border-right + margin-left + margin-right= 100px + 10px +10px + 2px + 2px +20px +20px = 164px; div实际所占的高度height = height(content高度) + padding-top + padding-bottom + border-top + border-bottom + margin-top +margin-bottom= 50px + 10px +

Removing inline styles using php

☆樱花仙子☆ 提交于 2020-01-12 07:17:18
问题 I am using php to output some rich text. How can I strip out the inline styles completely? The text will be pasted straight out of MS Word, or OpenOffice, and into a which uses TinyMCE, a Rich-Text editor which allows you to add basic HTML formatting to the text. However I want to remove the inline styles on the tags (see below), but preserve the tags themselves. <p style="margin-bottom: 0cm;">A patrol of Zograth apes came round the corner, causing Rosette to pull Rufus into a small alcove,

【题解】【UVA】UVA10181 15-Puzzle Problem

﹥>﹥吖頭↗ 提交于 2020-01-11 23:39:10
题外话: 老师:这些题都不难,都只是搜索+剪枝 我:不会…… 题面 十五数码问题 保证45步内有解 题解 IDA*入门题目,和八数码问题没差多少 ↑抱着天真想法的我 事实上,这题比八数码难了不少…… 首先,先像八数码一样把IDA*敲好 然后? 然后你发现样例你都T了 WDNMD ——发现自己样例TLE之后的我 冷静分析一波 首先我们从开始条件入手: 如果一开始就符合,那就不用搜了,直接输出空行 如果无解,也不用搜了,直接输出“This puzzle is not solvable.” 似乎很科学 问题是怎么判断无解呢 直接上结论, 证明在此 先将表格平铺,然后计算N=逆序数对之和,e=空白所在的行数。若N+e为偶数,则有解,反之无解 如此,我们可以减掉很多的无解情况 然后你满心欢喜地交上去 WDNMD*2 我们还要继续剪枝 我们知道,IDA*的效率很大程度上建立在估价函数的好坏上 然后我们看下我这种菜鸡写出来的估价函数 \(g(x)\) : inline int count() { int cnt=0; for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { if (a[i][j]!=ans[i][j]) { cnt++; } } } return cnt; } 发现了吗?它给出的下界太松了 考虑这样一个事实: 我们要让一个元素归位

C/C++中的const、static、inline、friend、template、virtual、异常机制等特性

徘徊边缘 提交于 2020-01-11 07:16:46
一、const const关键字的作用 (1)作用: 1)欲阻止一个变量被改变,可使用const,在定义该const变量时,需先初始化,以后就没有机会改变他了; 2)对指针而言,可以指定指针本身为const,也可以指定指针所指的数据为const,或二者同时指定为const; 3)在一个函数声明中,const可以修饰形参表明他是一个输入参数,在函数内部不可以改变其值; 4)对于类的成员函数,有时候必须指定其为const类型,表明其是一个常函数,不能修改类的成员变量; 5)对于类的成员函数,有时候必须指定其返回值为const类型,以使得其返回值不为“左值”。 const修饰变量 变量的值不能改变 const修饰指针 如果const位于*的左侧,则const就是用来修饰指针所指向的变量,即指针指向为常量 如果const位于*的右侧,const就是修饰指针本身,即指针本身是常量 指针常量:不能通过指针来修改变量的值。 常量指针:一直指向该变量,不能给该指针赋予其他地址 函数中使用const const修饰函数参数 表示参数不可变 若参数为引用,可以增加效率 const引用传递和函数按值传递的效果是一样的,但按值传递会先建立一个类对象的副本, 然后传递过去,而它直接传递地址,所以这种传递比按值传递更有效 const按值传递时只是外部对象的拷贝,值的改变不会对外部有什么影响

CSS 水平居中和垂直居中

浪尽此生 提交于 2020-01-11 05:05:35
转自: http://www.cnblogs.com/fu277/archive/2012/09/13/2400118.html 1.水平居中 (1) 文本、图片等行内元素的水平居中   给父元素设置text-align:center可以实现文本、图片等行内元素的水平居中。 (2) 确定宽度的块级元素的水平居中   通过设置margin-left:auto;和margin-right:auto;来实现的。 (3) 不确定宽度的块级元素的水平居中   方法一:   使用table标签,table本身并不是块级元素,如果不给它设定宽度的话,它的宽度由内部元素的宽度“撑起”,但即使不设定它的宽度,仅设置margin-left:auto;和margin-right:auto;就可以实现水平居中!   将需要居中的部分包含在table标签内,对table设置margin-left:auto;和margin-right:auto;就可以使table水平居中,间接使需要居中的部分水平居中。   缺点:增加了无语意标签,加深了标签的嵌套层数。 <style type="text/css">ul{list-style:none; margin:0; padding:0;}.wrap{ width:500px; height:100px;}table{margin-left:auto;margin

【算法学习笔记】并查集

坚强是说给别人听的谎言 提交于 2020-01-10 19:35:43
\(0.\) 简介 并查集是一种维护节点之间不相交集合关系的一种 树状 数据结构。在算法竞赛中较为常用。并查集的基本形态如下 \(1.\) 一些定义 代表元素 代表元素是指代表这个集合的元素,通常由根节点表示。如上图的4号节点就是这个集合的代表元素。 父亲节点 和其他的树状数据结构类似,父亲节点就是某一节点“上方”的节点。在并查集中,边的方向始终指向父亲节点。 \(2.\) 并查集的功能与基本实现方式 基本的并查集一般实现两种操作:合并集合,查找某个节点所在集合的代表元素。 并查集的初始化 一般的我们在初始状态时将每个元素看做独立的集合,即每个元素所在的集合就是自己。 for(rg int i=1;i<=n;i++) fa[i]=i; 上面代码中 \(fa[\ ]\) 就简单的实现了一个并查集。其中 \(fa[i]\) 代表编号为 \(i\) 的元素的父亲节点。 查找代表元素 并查集的实现结构是每个节点有一个指针指向父亲节点,代表元素(根)的指针指向自己。 所以可以递归地查找代表元素 inline int find(int x){ return fa[x]==x?x:find(fa[x]); } 上面的代码就实现了查找代表元素的操作。如果一个节点的父亲是他自己,那么这个节点就是并查集的代表元素,否则往上方跳,直到找到代表元素为止。 合并集合 zcy大神在某个地方讲过