Here

第4章 可变参数模板:4.1 可变参数模板

左心房为你撑大大i 提交于 2020-04-18 09:45:13
Chapter 4:Variadic Templates 第4章 可变参数模板 Since C++11, templates can have parameters that accept a variable number of template arguments. This feature allows the use of templates in places where you have to pass an arbitrary number of arguments of arbitrary types. A typical application is to pass an arbitrary number of parameters of arbitrary type through a class or framework. Another application is to provide generic code to process any number of parameters of any type. 从C++11开始,模板可以接受数量可变的模板参数。该特性允许我们在需要传入任意数量、任意类型参数的地方使用模板。经典的应用就是通过类或框架传递任意数量和任意类型的参数。另一个应用是提供泛型代码来处理任意数量和任意类型的参数。 4.1 Variadic

Android“只有创建视图层次结构的原始线程才能触摸其视图。”

好久不见. 提交于 2020-04-18 07:10:19
问题: I've built a simple music player in Android. 我已经在Android中构建了一个简单的音乐播放器。 The view for each song contains a SeekBar, implemented like this: 每首歌曲的视图都包含一个SeekBar,实现如下: public class Song extends Activity implements OnClickListener,Runnable { private SeekBar progress; private MediaPlayer mp; // ... private ServiceConnection onService = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder rawBinder) { appService = ((MPService.LocalBinder)rawBinder).getService(); // service that handles the MediaPlayer progress.setVisibility(SeekBar.VISIBLE); progress

vue组件之间的传值——中央事件总线与跨组件之间的通信($attrs、$listeners)

倖福魔咒の 提交于 2020-04-18 06:45:16
vue组件之间的通信有很多种方式,最常用到的就是父子组件之间的传值,但是当项目工程比较大的时候,就会出现兄弟组件之间的传值,跨级组件之间的传值。不可否认,这些都可以类似父子组件一级一级的转换传递,但是当项目比较大,功能比较复杂的时候,就会变得比较冗余,代码不利于维护;这时候可能会有很多人使用到vuex,但是如果项目中多个组件共享状态比较少,项目比较小,并且全局状态比较少,好像就没有使用vuex来管理数据的必要。 一、中央事件总线(eventBus) 主要是通过在要相互通信的兄弟组件之中,都注册引入一个新的vue实例,然后通过分别调用这个实例的事件触发和监听来实现通信和参数传递,也就是我们常说的bus车事件。 1、首先,全局注册一个新的vue实例,可以放在我们常用的vue项目文件中 js/event-bus.js import Vue from 'vue' export default new Vue() 2、如果不想全局引用可以,在使用的vue文件里使用,举个例子:contentLeft.vue,contentRight.vue 需要将contentLeft.vue与contentRight.vue互相通信 contentLeft.vue <template> <div> {{message}} <button @click="handleClick">test</button>

django权限管理

六月ゝ 毕业季﹏ 提交于 2020-04-16 16:32:28
【推荐阅读】微服务还能火多久?>>> 当我们为应用创建一个Models, 在同步到数据库里,django默认给了三个权限 ,就是 add, change, delete权限。 首先,我们创建一个perm_test的project, 然后再创建一个school的app. django- admin.py startproject perm_test cd perm_test python manage.py startapp school models: from django.db import models # Create your models here. class Student(models.Model): name = models.CharField( ' 姓名 ' , max_length=64 ) age = models.SmallIntegerField( ' 年龄 ' ) choices = ( ( 1, ' 男 ' ), ( 2, ' 女 ' ), ( 3, ' 未知 ' ) ) sex = models.SmallIntegerField( ' 性别 ' , choices=choices) admin.py from django.contrib import admin # Register your models here. from .

React Class功能与Hooks等效项

北城余情 提交于 2020-04-16 07:27:24
【推荐阅读】微服务还能火多久?>>> React Class功能与Hooks等效项 https://medium.com/soluto-engineering/react-class-features-vs-hooks-equivalents-745368dafdb3 I gave a talk during a recent meetup at Soluto HQ — Intro to React Hooks. While preparing for the presentation, I fell completely in love with Hooks. Although I was skeptical at first glance, I quickly realized how easy it is to use them and how they make perfect sense. You can really tell how much thought was put into the API and how it solves real life problems. You can find a video of my talk attached to this post (Hebrew only… Sorry!). In my talk I

第2章 类模板:2.5 类模板的特化

别来无恙 提交于 2020-04-16 07:27:05
【推荐阅读】微服务还能火多久?>>> 2.5 Specializations of Class Templates 2.5 类模板的特化 You can specialize a class template for certain template arguments. Similar to the overloading of function templates (see Section 1.5 on page 15), specializing class templates allows you to optimize implementations for certain types or to fix a misbehavior of certain types for an instantiation of the class template. However, if you specialize a class template, you must also specialize all member functions. 你可以用模板实参来特化类模板,和函数模板的重载类似(见第15页1.5节)。你可以优化基于某种特定类型的实现,或者修复某种特定类型在实例化类模板时所出现的不足。但是,当你特化类模板时,必须同时特化所有的成员函数。 Although it is

c++线程使用

ε祈祈猫儿з 提交于 2020-04-15 16:47:34
【推荐阅读】微服务还能火多久?>>> 1,简介 C++11中加入了<thread>头文件,此头文件主要声明了std::thread线程类。C++11的标准类std::thread对线程进行了封装,定义了C++11标准中的一些表示线程的类、用于互斥访问的类与方法等。应用C++11中的std::thread便于多线程程序的移值。 std::thread类成员函数: (1)、get_id:获取线程ID,返回一个类型为std::thread::id的对象。 (2)、joinable:检查线程是否可被join。检查thread对象是否标识一个活动(active)的可行性线程。缺省构造的thread对象、已经完成join的thread对象、已经detach的thread对象都不是joinable。 (3)、join:调用该函数会阻塞当前线程。阻塞调用者(caller)所在的线程直至被join的std::thread对象标识的线程执行结束。 (4)、detach:将当前线程对象所代表的执行实例与该线程对象分离,使得线程的执行可以单独进行。一旦线程执行完毕,它所分配的资源将会被释放。 (5)、native_handle:该函数返回与std::thread具体实现相关的线程句柄。native_handle_type是连接thread类和操作系统SDK API之间的桥梁,如在Linux g++

ss5安装和配置

我的梦境 提交于 2020-04-14 07:41:38
【今日推荐】:为什么一到面试就懵逼!>>> wget https://nchc.dl.sourceforge.net/project/ss5/ss5/3.8.9-8/ss5-3.8.9-8.tar.gz yum -y install gcc gcc-c++ automake make pam-devel openldap-devel cyrus-sasl-devel tar xzf ss5-3.8.9-8.tar.gz cd ss5-3.8.9 ./configure make make install chmod +x /etc/init.d/ss5 chkconfig --add ss5 chkconfig --level 345 ss5 on 开启用户名密码验证机制,找到以下两行取消注释即可 vi /etc/opt/ss5/ss5.conf auth 0.0.0.0/0 - u permit u 0.0.0.0/0 - 0.0.0.0/0 - - - - - 设置用户名密码,一行一个账号,用户名和密码之间用空格间隔 vi /etc/opt/ss5/ss5.passwd user1 pwd1 user2 pwd2 设置ss5端口 vi /etc/sysconfig/ss5 # Add startup option here SS5_OPTS=" -u root -b 0.0.0

Algebraic Data Type 及其在 Haskell 和 Scala 中的表现

大兔子大兔子 提交于 2020-04-13 19:53:33
【今日推荐】:为什么一到面试就懵逼!>>> http://songkun.me/2018/07/12/2018-07-12-adt-in-haskell-and-scala/ 函数式编程接触久了以后,我们会发现很多 FP 语言(这里指静态 FP 语言)具有不少类似的语言特性,这非常自然,因为语言特性就那么多,好用、实用的特性更少,这一方面造成了语言之间的同质化,另一方面也减轻了我们语言切换的成本,算是有利也有弊吧。 常见的静态函数式语言有 Haskell、Standard ML、OCaml、Scala 等,它们之间非常类似,共有的特性有: first-class function(匿名函数、高阶函数、闭包、柯里化、部分应用函数…) algebraic data type 模式匹配 类型推断 各个语言也有自己相对独特的特性,比如 Haskell 的 typeclass,Standard ML 和 OCaml 的模块,Scala 的私货就更多了,为了兼容 OO 和 FP 做了很多设计上的妥协,也引入了很多概念。 函数式编程语言也有动态、静态之分,上面列举的都是静态语言,动态语言则以 Lisp 为代表,包括:Scheme、Racket、Clojure、Erlang、Elixir 等,由于动态类型的限制,它们没有 algebraic data type、类型推断等类型系统相关的特性。

Perl多线程(2):数据共享和线程安全

纵然是瞬间 提交于 2020-04-13 17:10:09
【今日推荐】:为什么一到面试就懵逼!>>> 线程数据共享 在介绍Perl解释器线程的时候一直强调, Perl解释器线程在被创建出来的时候,将从父线程中拷贝数据到子线程中,使得数据是线程私有的,并且数据是线程隔离的。如果真的想要在线程间共享数据,需要显式使用 threads::shared 模块来扩展threads模块的功能 。这个模块必须在先导入了threads模块的情况下使用,否则 threads::shared 模块里的功能都将没效果。 use threads; use threads::shared; 要共享数据,只需使用 threads::shared 模块的share方法即可,也可以直接将数据标记上 :shared 属性的方式来共享。例如: my $answer = 43; my @arr = qw(1 2 3); share($answer); share(@arr); my $answer :shared = 43; my @arr :shared = qw(1 2 3); my %hash :shared = (one=>1, two=>2, three=>3); 使用share()和 :shared 的区别在于后面这种标记的方式是在编译期间完成的。另外,使用 :shared 属性标记的方式可以直接共享引用类型的数据,但是share()不允许