auto

Perfect forwarding to a member function of a data member?

可紊 提交于 2019-12-07 14:19:35
问题 Consider a class that has a private std::vector data member: class MyClass { private: std::vector<double> _data; public: template <class... Args> /* something */ insert(Args&&... args) /* something */ { return _data.insert(std::forward<Args>(args)...); } }; What is the correct syntax (using C++14 auto/variadic templates/forward...) to transfer a given function of _data to MyClass (for example insert here) and provide the same interface for the user? 回答1: The correct syntax is this: class

IOS 6 自动布局 入门 2

拟墨画扇 提交于 2019-12-07 01:50:43
来自Ray:恭喜各位!你们已经通过宣传 ios feast 提前解锁了第一个有关IOS6的教程。 目前这份教程只是我们的新书 iOS 6 By Tutorials 里面某个章节的精简版。这份教程由同样著作过 iOS Apprentice Series 的Matthijs Hollemans 完成,开始体验吧! 这份教程由IOS 教程小组的组员 Matthijs Hollemans 发布, Matthijs 既是一位经验丰富的IOS程序员又是一名资深老到的界面设计者。. 在 这系列教程的第一部分 你见识到了旧的“struts-and-springs” 模式不能简单的解决所有的用户界面布局问题。新的IOS 6特征是一种解决方案,但因为这个技术是如此的有效,它使用起来还是有点小棘手的。在这系列教程的第二部分也是最后一部分, 你将继续学习constraint的概念以及如何运用他们! 大胆尝试constraint 也许你已经注意在canvas里面到有些T型状对象看上去比其他的要粗一点。这些加粗的,我们称之为 user constraints ,你删除它们后的效果和删除细的是不同的。当你删除一个 user constraints ,Interface Builder经常会自动在删除的地方放置一个不可删除的constraint来代替之。我马上就会讲到为什么会这样。 在文档概要图中,user

IOS 6 自动布局 入门-1

ⅰ亾dé卋堺 提交于 2019-12-07 01:50:19
来自Ray:恭喜各位!你们已经通过宣传ios feast提前解锁了第一个有关IOS6的教程。 目前这份教程只是我们的新书iOS 6 By Tutorials里面某个章节的精简版。这份教程由同样著作过iOS Apprentice Series 的Matthijs Hollemans 完成,开始体验吧! 这份教程由IOS 教程小组的组员 Matthijs Hollemans 发布, Matthijs 既是一位经验丰富的IOS程序员又是一名资深老到的界面设计者。 你是否曾经因为尝试想让你的应用同时在景观方向(横版)以及肖像方向(竖版)看上去不错而感到受挫?是否为了让应用同时支持iPhone以及iPad的模型尺寸而抓狂?现在我们可以不用为此而担心了,我有个好消息带给大家! 通常来说,如果屏幕是固定尺寸,那么设计它的用户界面不会很难,但如果屏幕的frame需要能够变化,那么其中各个UI元素的位置以及尺寸也必须为了适应新的尺寸做相应的变化。 目前为止,即使你的界面设计是在合理的复杂度内,你也必须要为之写许多代码来适应变化的布局。现在我相信你会很高兴听到这种情况将不会发生了-对于iPhone与iPad IOS6 带来了一个非常了不起的特征:自动布局。 自动布局不仅能给你的应用带来各种屏幕尺寸设计的支持,做为额外的惊喜,它还能使设计中的各种小事比如多语言环境支持

Auto Layout + Manual Layout 混用

限于喜欢 提交于 2019-12-07 01:49:59
约束代码混用的问题 无数人趟过此坑,大部分人在坑中一蹶不振,小部分人爬起来也是跌跌撞撞。 有很多人都说auto layout和manual layout的坐标设置是不能混用的,会导致出现布局问题。首先声明一点,autolayout和manuallayout是可以混用的。用的时机很重要,auto layout和manual layout有各自的生命周期和作用域,区分他们两个的作用时间很关键,头脑中一定要清楚你所添加的每条约束,在什么时间场合,会造成什么后果。否则,布局就会和预想的不同,各种奇怪的布局问题也就接踵而至。 1)视图的生命周期顺序 我们在controller视图上面用auto layout添加了一个subview,并在各个系统调用声明周期方法中做了打印处理,结果如下: 其中前面带有“-”符号的表示的是subview视图的打印。 autolayout的作用范围是从上往下第三个方法-updateConstraints一直到viewDidLayoutSubviews,这期间,系统是通过view上的约束来计算view上的布局。而我们一般习惯将布局写在viewDidLoad里面,这就是我们为什么总是无法用manual layout的方法去修改我们的布局。 要想修改布局,必须要在autolayout结束之后才会起作用,否则会被系统将我们的布局按照autolayout重新刷新

vim c/c++智能补全插件

China☆狼群 提交于 2019-12-06 16:12:53
我很喜欢vim,而且一直用,不过对于c/c++只能补全一直都没有一个很好的解决方案,虽然有个插件(omnicomplete)功能比较强大,跟eclipse等IDE比起来还是很有差距的,特别是对于类的智能补全。 前些天网上找到一个功能甚是强大的插件( clang complete ),可以很好的解决这个问题,个人认为完全可以取代omnicomplete。这个插件依赖于clang编译器,这个编译器安装很简单,一般流行的linux发行版本的软件仓库中都有,比如在debian或ubuntu中可以这样, sudo apt-get install clang 然后就是就是安装插件了, clang complete , 如何安装,自己看介绍吧。使用方法就是当你在类名或实例后输入.或者->时,vim会自动根据clang编译器提供的信息不全该类提供的方法,当然如果你的代码中有错,可就不行哦。因为你的代码补全信息都是要通过clang实时编译器编译的。 贴一张效果图,个人强力推荐! 有兴趣的朋友可以打开原文链接看看。 原文链接: http://blog.chmd.fr/vim-complete-c-accurately-pulling-informations-from-the-compiler-with-gccsense-and-clang_complete.html 来源: oschina 链接:

AndroidManifest.xml 详解

 ̄綄美尐妖づ 提交于 2019-12-06 15:47:48
AndroidManifest.xml 是每个android程序中必须的文件,它位于整个项目的根目录。我们每天都在使用这个文件,往里面配置程序运行所必要的组件,权限,以及一些相关信息。但是对于这个文件,我们真正又了解多少了,还是只是停留在只会简单的配置,而不明白其中的具体含义,以及为什么要这样设置?今天就让我们来详细的学习一下这个文件里各项参数的具体含义,因为它是整个应用的入口,所以有助于我们更加深入的理解Android。 一、概述:   AndroidManifest.xml是Android应用的入口文件,它描述了package中暴露的组件(activities, services, 等等),他们各自的实现类,各种能被处理的数据和启动位置。 除了能声明程序中的Activities, ContentProviders, Services, 和Intent Receivers,还能指定permissions和instrumentation(安全控制和测试)。    二、结构图 <?xmlversion="1.0"encoding="utf-8"?> <manifest> <uses-sdk/> <uses-configuration/> <uses-feature/> <uses-permission/> <permission/> <permission-tree/>

Disallow the use of auto for a given class, C++14 vs. C++17 update

谁说我不能喝 提交于 2019-12-06 15:31:25
问题 What is the feature that allows me use auto for non-copyable (and non-movable) types in C++17 and didn't for C++14? Consider the following code: struct A{ A(A const&)=delete; A(A&&)=delete; }; int main(){ auto a1 = A{}; // ok in C++17, not ok in C++14 auto&& a2 = A{}; // ok in C++17, ok in C++14 } It turns out that this was invalid code in C++14 but it is valid in C++17. The behavior is consistent in clang and gcc: https://godbolt.org/z/af8mEc The reason I ask is because until recently I was

Is C++11 auto type dangerous? [duplicate]

妖精的绣舞 提交于 2019-12-06 10:51:19
This question already has answers here : Closed 7 years ago . Possible Duplicate: How much is too much with C++0x auto keyword The new keyword “auto”; When should it be used to declare a variable type? In C++11, Typing a variable auto instead of, say, int , will let the compiler automatically use the right type, deduced from its initialization context. This comes super handy in situations where the type is obvious but boring to write. Are there pitfalls to be aware of, or reasons why someone would avoid using that? My personal experience is auto is handy for generic code, or things like range

how to SFINAE for enabling member function returning `auto`

假如想象 提交于 2019-12-06 08:13:50
问题 In template meta programming, one can use SFINAE on the return type to choose a certain template member function, i.e. template<int N> struct A { int sum() const noexcept { return _sum<N-1>(); } private: int _data[N]; template<int I> typename std::enable_if< I,int>::type _sum() const noexcept { return _sum<I-1>() + _data[I]; } template<int I> typename std::enable_if<!I,int>::type _sum() const noexcept { return _data[I]; } }; However, this won't work if the function in question ( _sum() in

auto, decltype(auto) and trailing return type

无人久伴 提交于 2019-12-05 23:15:35
Is there a difference between: template <class T> constexpr decltype(auto) f(T&& x) -> decltype(std::get<0>(std::forward<T>(x))) { return std::get<0>(std::forward<T>(x)); } and: template <class T> constexpr auto f(T&& x) -> decltype(std::get<0>(std::forward<T>(x))) { return std::get<0>(std::forward<T>(x)); } and if so, what is it, and which one should I use for perfect forwarding? kennytm Trailing return type should only be used with auto The point of decltype(auto) vs auto is to distinguish the case whether the return type should be a reference or value . But in your case the return type is