Tuesday, August 20, 2013

Boost at nuget.org

It's unofficial but it works https://www.nuget.org/packages/boost/. For Visual Studio 2012, supported platforms: Win32 and x64.

It's huge 235Mb and takes about half an hour to install.

  1. Open your C++ project. Or create a new one.
  2. Open Tools | Library Package Manager | Manage NuGet Packages for Solution....
  3. Search for "boost" in Online | NuGet Official Package Source (Include Prerelease).
  4. Press the Install button.
  5. Wait for about 10 minutes.
  6. Select your C++ project and press Ok.
  7. Wait for another 10 minutes.
  8. Close the dialogs.
  9. Include some boost header files. For example: #include <boost/atomic.hpp>
  10. Build the project.

Update

The updated boost package doesn't contain compiled libraries (.lib/.dll) any more. Now it's only 15Mb. I've created separate packages for the boost compiled libraries:

Sunday, February 13, 2011

Nemerle at Wikipedia.

The article about Nemerle has been removed from Wikipedia as a non-notable programming language.

Tuesday, February 1, 2011

INumeric policy.

Policies:
interface INumericPolicy<T>
{
    T Zero();
    T Add(T a, T b);
    ...
}

class All: INumericPolicy<int>, INumericPolicy<long>, ...
{
    ...
    public static All P = new All();
}
User's algorithms:
static class Algorithms
{
    public static T Sum<P, T>(this P p, params T[] a)
        where P: INumericPolicy<T>
    {
        var r = p.Zero();
        foreach(var i in a)
        {
            r = p.Add(r, i);
        }
        return r;
    }

    ...
}
Usage:
int i = All.P.Sum(1, 2, 3, 4, 5);
long l = All.P.Sum(1L, 2, 3, 4, 5);

Monday, January 31, 2011

.NET/C# 5 wish list

  1. Merge WPF and Silverlight. .NET Framework and .NET Compact Framework. It would be better to have just different profiles of framework like (.NET client profile) instead of different frameworks.
  2. Non-nullable references
    string! x = "xxx";
    
  3. Discriminated unions:
    union MyUnion: Enum
    {
        case Enum.Red: RedClass;
        case Enum.Green: GreenClass;
        ...
    }
    
  4. INumeric interface for standard numeric types.
    struct UInt32: INumeric<UInt32>
    {
    ...
    }
    
  5. Fixed size arrays
    byte[10] x;
    
  6. Operator extensions (syntax sugar):
    public static class Extensions
    {
        public static T operator+ <T>(T a, T b) where T: INumeric<T>
        ...
    }
    
  7. Polymorphic up cast:
    class A: B { ... }
    ...
    new A() up B
    
    Update: No needs any more. Solution:
    public static class Extension
    {
        public static T UpCast<T>(T derived)
        {
            return derived;
        }
    }
    
    Example:
    new B().UpCast<A>()
    
  8. Force use 'using' keyword for some classes.
    using class My: IDisposable
    {
        ....
    }
    
    ...
    
    // Ok.
    using(var my = new My())
    {
    }
    
    // Compilation error.
    {
     var my = new My();
    }
    
    // Ok.
    return new My();
    
  9. Units of measurements. As in F# http://msdn.microsoft.com/en-us/library/dd233243.aspx.
  10. Named code blocks.
    code Block
    {
      foreach(var x in M)
      {
        foreach(var y in x)
        {
          if(y)
            break Block; 
        }
      }
    }
    
  11. A reference to an anonymous delegate inside the delegate.
    Control.Selected += (s, e) =>
    {
        ...
        Control.Selected -= this function;
    }
    

Tuesday, December 28, 2010

.NET Frameworks

Class Library / Windows Metro style

  • Runtime: ?
  • Framework: .NETCore
  • Version: 4.5

Class Library / .NET Framework 4 Client

  • Runtime: 4.0.30319
  • Framework: .NETFramework
  • Version: 4.0
  • Profile: Client

Windows Game Library / .NET Framework 4 Client

  • Runtime: 4.0.30319
  • Framework: .NETFramework
  • Version: 4.0
  • Profile: Client

Xbox 360 Game Library

  • Runtime: 2.0.50727

Silverlight Class Library / Silverlight 4

  • Runtime: 2.0.50727
  • Framework: Silverlight
  • Version: 4.0

Silverlight for Windows Phone 7.1

  • Runtime: ?
  • Framework: Silverlight
  • Version: 4.0
  • Profile: WindowsPhone71

Silverlight for Windows Phone 7.0

  • Runtime: 2.0.50727
  • Framework: Silverlight
  • Version: 4.0
  • Profile: WindowsPhone

Silverlight Class Library / Silverlight 3

  • Runtime: 2.0.50727

Windows Phone Game Library

  • Runtime: 2.0.50727

Friday, December 10, 2010

CSS gradient on C#

CSS gradient on C# using CityLizard Framework. Works in IE 5.5-8.0, FireFox 3.6, Chrome 8.0, Safari 5.0 and Opera 10.
namespace Css
{
    using S = www_w3_org._2000.svg.X;
    using D = System.Drawing;

    class Gradient
    {
        class Svg : S
        {
            public T.svg Gradient(string start, string end)
            {
                return
                    svg_(width: "100%", height: "100%")
                        [defs
                            [linearGradient_(
                                id: "grad",
                                x1: "0",
                                y1: "0",
                                x2: "0",
                                y2: "100%")
                                [stop_(offset: "0", stop_color: start)]
                                [stop_(offset: "1", stop_color: end)]
                            ]
                        ]
                        [rect_(
                            width: "100%",
                            height: "100%",
                            x: "0",
                            y: "0",
                            style: "fill:url(#grad)")
                        ];
            }
        }

        static string X2(byte x)
        {
            return x.ToString("X2");
        }

        static string ToString(D.Color c)
        {
            return "#" + X2(c.R) + X2(c.G) + X2(c.B);
        }

        static byte Avg(byte a, byte b)
        {
            return (byte)((a + b) / 2);
        }

        static D.Color Avg(D.Color a, D.Color b)
        {
            return D.Color.FromArgb(
                Avg(a.R, b.R), Avg(a.G, b.G), Avg(a.B, b.B));
        }

        public static string Y(D.Color Start, D.Color End)
        {
            var s = ToString(Start);
            var e = ToString(End);
            var svgB = new Svg().Gradient(s, e).ToString();
            var svg = "";
            foreach (var c in svgB)
            {
                var x = (int)c;
                if (x <= 0x40)
                {
                    svg += "%" + x.ToString("X2");
                }
                else
                {
                    svg += c;
                }
            }
            // Next browsers to test: Opera 11 (hopefully it has CSS gradient), 
            // IE 9.
            return
                // for other browsers.
                "background: " + ToString(Avg(Start, End)) + ";" +

                // Opera 10. It also works for Chrome and Safari.
                "background: url(\"data:image/svg+xml," + svg + "\");" +

                // IE 5.5-8.0.
                "filter: progid:DXImageTransform.Microsoft.gradient(" +
                "startColorstr='" +
                s +
                "', endColorstr='" +
                e +
                "');" +

                // webkit browsers (Chrome, Safari). It is not required 
                // because SVG gradient for Opera works fine for these 
                // browsers.
                /*
                "background: -webkit-gradient(" +
                "linear, left top, left bottom, from(" + 
                s + 
                "), to(" + 
                e + 
                "));" +
                */

                // FireFox 3.6+
                "background: -moz-linear-gradient(top,  " + s + ", " + e + ");";
        }
    }
}

Monday, December 6, 2010

List of free tools

Tools

.

Browsers

Others