Commit d8bd2862 authored by CHAMONT David's avatar CHAMONT David
Browse files

details...

parent d1b6b652
......@@ -110,7 +110,7 @@
"template< typename IterT, typename DistT >\n",
"void jump( IterT & iter, DistT d )\n",
" {\n",
" if ( typeid(typename std::iterator_traits<IterT>::iterator_category) ==\n",
" if ( typeid(typename IterT::iterator_category) ==\n",
" typeid(std::random_access_iterator_tag) )\n",
" { iter += d ; } \n",
" else\n",
......@@ -180,7 +180,7 @@
"\n",
"template< typename IterT, typename DistT >\n",
"void jump( IterT & iter, DistT d )\n",
" { jump_impl( iter, d, typename IterT::iterator_category() ) ; }"
" { jump_impl( iter, d, (typename IterT::iterator_category)() ) ; }"
]
},
{
......
......@@ -154,7 +154,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 26,
"metadata": {
"slideshow": {
"slide_type": "subslide"
......@@ -173,6 +173,7 @@
"%%file tmp.sfinae.cpp\n",
"\n",
"#include <iostream>\n",
"#include <limits>\n",
"\n",
"bool equal( unsigned e1, unsigned e2 )\n",
" {\n",
......@@ -184,7 +185,7 @@
"typename T::bool_type equal( T e1, T e2 )\n",
" {\n",
" std::cout<<\"(template)\"<<std::endl ;\n",
" return abs(e1-e2)<1e-6 ;\n",
" return abs(e1-e2)<std::numeric_limits<T>::epsilon() ;\n",
" }\n",
"\n",
"int main()\n",
......@@ -193,7 +194,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 27,
"metadata": {
"attributes": {
"classes": [
......@@ -212,7 +213,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 28,
"metadata": {
"attributes": {
"classes": [
......@@ -437,19 +438,38 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 29,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[1minput_line_7:4:8: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno member named 'cout' in namespace 'std'\u001b[0m\n",
" std::cout<<\"(template)\"<<std::endl ;\n",
"\u001b[0;1;32m ~~~~~^\n",
"\u001b[0m"
]
},
{
"ename": "Interpreter Error",
"evalue": "",
"output_type": "error",
"traceback": [
"Interpreter Error: "
]
}
],
"source": [
"template <typename T>\n",
"std::enable_if_t<std::is_floating_point_v<T>,T> equal( T e1, T e2 )\n",
"bool equal( T e1, T e2, std::enable_if_t<std::is_floating_point_v<T>,T> epsilon = 1e-6 )\n",
" {\n",
" std::cout<<\"(template)\"<<std::endl ;\n",
" return abs(e1-e2)<1e-6 ;\n",
" return abs(e1-e2)<epsilon ;\n",
" }"
]
},
......@@ -466,7 +486,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 30,
"metadata": {
"attributes": {
"classes": [
......@@ -500,10 +520,10 @@
" }\n",
"\n",
"template< typename T, std::enable_if_t<std::is_floating_point_v<T>> * = nullptr >\n",
"bool equal( T e1, T e2 )\n",
"bool equal( T e1, T e2, T epsilon = 1e-6 )\n",
" {\n",
" std::cout<<\"(template)\"<<std::endl ;\n",
" return abs(e1-e2)<1e-6 ;\n",
" return abs(e1-e2)<epsilon ;\n",
" }\n",
"\n",
"int main()\n",
......@@ -512,7 +532,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 31,
"metadata": {
"attributes": {
"classes": [
......@@ -531,7 +551,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 32,
"metadata": {
"slideshow": {
"slide_type": "-"
......@@ -570,7 +590,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 33,
"metadata": {
"attributes": {
"classes": [
......@@ -602,8 +622,8 @@
" { std::cout<<\"(non floating)\"<<std::endl ; return (e1==e2) ; }\n",
"\n",
"template< typename T, std::enable_if_t<std::is_floating_point_v<T>> * = nullptr >\n",
"bool equal( T e1, T e2 )\n",
" { std::cout<<\"(floating)\"<<std::endl ; return abs(e1-e2)<1e-6 ; }\n",
"bool equal( T e1, T e2, T epsilon = 1e-6 )\n",
" { std::cout<<\"(floating)\"<<std::endl ; return abs(e1-e2)<epsilon ; }\n",
"\n",
"int main()\n",
" {\n",
......
......@@ -1154,7 +1154,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
"version": "3.9.7"
}
},
"nbformat": 4,
......
......@@ -2,7 +2,11 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Template Meta Programming\n",
"\n",
......@@ -15,7 +19,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"## Sources\n",
"\n",
......@@ -24,7 +32,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"© *CNRS 2021* \n",
"*This document was created by David Chamont. It is available under the [License Creative Commons - Attribution - No commercial use - Shared under the conditions 4.0 International](http://creativecommons.org/licenses/by-nc-sa/4.0/)*"
......@@ -32,6 +44,7 @@
}
],
"metadata": {
"celltoolbar": "Diaporama",
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment